var controllers = angular.module('controllers',
                                 ['services', 'directives', 'ngDialog', 'gobals', 'ui.bootstrap']);
//主页
controllers.controller('IndexCtrl',
                       function ($scope, $rootScope, locationService, $location, gobalService,
                                 settingService) {

                           var nav = angular.element('nav');

                           if (nav) {
                               nav.hide();
                           }

                           //spinner6
                           var width = $('.fakeloader').width();
                           var height = $('.fakeloader').height();

                           jQuery(".spinner6").css({
                                                       'position': 'fixed',
                                                       'left': width / 2 - 35,
                                                       'top': height / 2 - 15
                                                   });

                           var cfg = gobalService.config();

                           if (isFromWx() && _obj.code && !$rootScope.openId) {
                               //换取access token 和 openId
                               settingService.authInfo(cfg.sysKey, cfg.appId, _obj.code)
                                   .then(function (authInfo) {

                                       if (authInfo.code == 0) {

                                           var openId = authInfo.data;

                                           $rootScope.openId = openId; //验证信息

                                           //跳转到业务界面
                                           navToBusiness();

                                       } else {
                                           $location.path('/index');//跳转到首页
                                       }
                                   }, function (error) {
                                       $location.path('/index');//跳转到首页
                                   });

                           } else {
                               //跳转到业务界面
                               navToBusiness();
                           }

                           function navToBusiness() {
                               //定位
                               locationService.locateMe($rootScope).then(function () {

                                   settingService.getServices(cfg.sysKey).then(function (result) {
                                       if (result.daijia) {
                                           $location.path('/daijia');
                                       }
                                       else if (result.zhuanche) {
                                           $location.path('/zhuanche');
                                       }
                                       else if (result.paotui) {
                                           $location.path('/paotui');
                                       }
                                       else if (result.xiche) {
                                           $location.path('/xiche');
                                       }
                                       else if (result.zhuanxian) {
                                           $location.path('/zhuanxian');
                                       }

                                   });

                               }, function (error) {
                                   if (error.code == 1) {
                                       alert('没有权限使用地理定位API');
                                   } else if (error.code == 2) {
                                       alert('无法确定设备的位置');
                                   } else if (error.code == 3) {
                                       alert('定位超时');
                                   }
                               });
                           }

                       });

//代驾
controllers.controller('DaijiaCtrl',
                       function ($scope, $rootScope, $routeParams, $sce, $location, $uibModal,
                                 $window, gobalService,settingService, locationService, daijiaService, userService,
                                 ngDialog) {

							ngDialog.closeAll();
                           var cfg = gobalService.config();
                           var money =null;

                           $scope.daijia = {};

                           var nav = angular.element('nav');

                           if (nav) {
                               nav.show();
                           }

                           angular.element('ul.nav_line > li > a').removeClass('nav_click');
                           angular.element('#daijia').addClass('nav_click');
                           
                           

                           if (isFromWx()) {
                               if ($rootScope.openId) {
                                   userService.findWxBind(cfg.sysKey, $rootScope.openId)
                                       .then(function (result) {
                                           if (result.code == 0) {
                                               var bindData = result.data;
                                               $scope.daijia.phone = bindData.phone;
                                               $scope.daijia.passengerId = bindData.passengerId;

                                               $rootScope.passengerId = bindData.passengerId;
                                               $rootScope.passengerPhone = bindData.phone;
                                               runningDaijia();
                                          
                                               
                                           }

                                       });
                               } else {

                                   $location.path('/index'); //跳转到首页
                               }

                           } 
                           
                           function runningDaijia(){
                        	   
                               
                               
                               daijiaService.findDjOrder(cfg.sysKey, $scope.daijia.passengerId)
                               .then(function (result) {
                                   if (result != null && result.length != 0) {
//			alert("您有未完成的代驾订单");
                                       var dialog = ngDialog.open({
                                                                      template: '/assets/v4/partials/notorder.html',
                                                                      overlay: true,
                                                                      showClose: true,
                                                                      scope: $scope
                                                                  });

                                       $scope.into = function () {

                                           var promise = daijiaService.findOrder(cfg.sysKey,
                                                                                 result[0].id);

                                           promise.then(function (fruit) {
                                               if (fruit.success) {
                                                   dialog.close(true);
                                                   var orderInfo = fruit.data;

                                                   $scope.bookTime = orderInfo.serverTime;
                                                   $scope.beginAddress = orderInfo.fromPlace;
                                                   $scope.endAddress = orderInfo.toPlace;
                                                   $scope.phone = orderInfo.clientPhone;

                                                   if (orderInfo.status == 0 || orderInfo.status
                                                                                == 1
                                                       || orderInfo.status == 2 || orderInfo.status
                                                                                   == 7) { //司机已接单
                                                	   
                                                	   $location.path('/execute').search({
                                                           'orderId': orderInfo.id,
                                                           'type': 'daijia'
                                                       });

                                                       /*if (orderInfo.treatment) { //司机已经确认支付信息
                                                           //跳转到支付界面
                                                           $location.path('/payment').search({
                                                                                                 'orderId': orderInfo.id,
                                                                                                 'type': 'daijia'
                                                                                             });
                                                           return;
                                                       }

                                                       //跳转接单界面
                                                       
                                                       if (orderInfo.status == 0 || orderInfo.status
                                                                                    == 1) {

                                                           setTimeout(runningDaijia(), 5000);//请求成功间隔一秒再次请求

                                                       }*/

                                                   }
                                                   else if (orderInfo.status == 3
                                                            || orderInfo.status == 6) { //已完成
                                                       //跳转完成界面
                                                       alert('订单已完成');
                                                       $location.path("/index");
                                                   }

                                               }

                                           }, function (error) {

                                               setTimeout(runningDaijia(), 5000);//请求成功间隔一秒再次请求

                                           });

                                       }
                                       $scope.back = function () {
                                           $window.history.back();
                                       }

                                       
                                   }
                               });
                          }  

                               /*$scope.daijia.passengerId = 21;
                               $scope.daijia.phone = 13880445647;
                               runningDaijia();*/
                           
                           
                           
                           /**
                            * 查询广告信息
                            */
                           function getAdvs(locationInfo) {
                               var promise = settingService.getAdvs(cfg.sysKey, cfg.ack,
                                                                    locationInfo.point.lat,
                                                                    locationInfo.point.lng,
                                                                    $rootScope.passengerId);
                               promise.then(function (result) {
                                   if (result.code == 0) {
                                       var imgs = result.data;
                                       if (imgs) {
                                           var li = '<div class="main_image"><ul >';

                                           for (var i = 0; i < imgs.length; i++) {
                                               li +=
                                                   '<li><a href="' + imgs[i].linkAddress
                                                   + '"><img src="http://' + result.address + '/'
                                                   + imgs[i].picture + '"/></a></li>'
                                           }

                                           li +=
                                               '</ul> <a href="javascript:;" id="btn_prev"></a><a href="javascript:;" id="btn_next"></a></div>';

                                           jQuery("#adv").html(li);
                                           //调用滚动
                                           silder();
                                       }
                                   }
                               });
                           }

                           $scope.tip = $sce.trustAsHtml('<p>正在为您查询附近司机...</p>');
                           $scope.hideBeginTip = true;
                           $scope.hideEndTip = true;

                           $scope.hidePois = function () {

                               $scope.hideBeginTip = true;
                               $scope.hideEndTip = true;

                           }

                           /**
                            * 过滤不合法的poi
                            *
                            * @param results
                            * @returns {Array.<*>}
                            */
                           function filterPoi(results) {

                               var arr = [];
                               for (var i = 0; i < results.length; i++) {
                                   var poi = results[i];
                                   if (poi.location) {
                                       arr.push(poi);
                                   }
                               }

                               return arr.reverse();
                           }
                           
                           

                           /**
                            * 预算费用
                            *
                            * @param passengerId
                            * @param beginLat
                            * @param beginLng
                            * @param endLat
                            * @param endLng
                            */
                           function calculationFee(passengerId, beginLat, beginLng, endLat,
                                                   endLng) {
                        	   

                               $scope.feemsg = $sce.trustAsHtml('正在为您预估费用...');

                               var promise = daijiaService.calculation(cfg.sysKey, cfg.ack,
                                                                       passengerId, beginLat,
                                                                       beginLng, endLat, endLng);
                               promise.then(function (result) {

                                   if (result.success) {

                                       $scope.feeDetail = result;
                                       money = result.money;

                                       $scope.feemsg =
                                           $sce.trustAsHtml(
                                               '约<b style="font-size: 25px;">' + result.money.toFixed(1)
                                               + '</b>元<img src="/assets/v4/img/wenhao.png" width="24" height="24"/>');
                                   } else {

                                       $scope.feeDetail = null;
                                       $scope.feemsg = $sce.trustAsHtml('未能为您预估费用.');
                                   }

                               }, function (error) {
                                   $scope.feeDetail = null;
                                   $scope.feemsg = $sce.trustAsHtml('未能为您预估费用.');
                               });

                           }

                           $scope.showFeeDetail = function () {

                               if ($scope.feeDetail) {

                                   if ($scope.feeDetail.pay_detail) {
                                       $scope.feeDetail.detail =
                                           $sce.trustAsHtml(
                                               $scope.feeDetail.pay_detail.replace(/\n/g, "<br/>"));
                                   }
                                   //弹出支付提示
                                   ngDialog.open({
                                                     template: '/assets/v4/partials/feeInfo.html',
                                                     overlay: true,
                                                     showClose: true,
                                                     scope: $scope
                                                 });

                               }
                           }

                           /**
                            * 预约代驾订单
                            *
                            * @param beginAddress
                            * @param beginAddressDetail
                            * @param beginLat
                            * @param beginLng
                            * @param endAddress
                            * @param endAddressDetail
                            * @param endLat
                            * @param endLng
                            * @param phone
                            */
                           function makeAnAppointment(beginAddress, beginAddressDetail, beginLat,
                                                      beginLng, endAddress, endAddressDetail,
                                                      endLat, endLng, phone, money) {

                               var promise = daijiaService.makeAnAppointment(cfg.sysKey, cfg.ack,
                                                                             beginAddress,
                                                                             beginAddressDetail,
                                                                             beginLat, beginLng,
                                                                             endAddress,
                                                                             endAddressDetail,
                                                                             endLat, endLng, phone,money,
                                                                             $rootScope.openId);

                               promise.then(function (result) {

                                   if (result.success) {
                                	   $(".main_image").hide();

                                       $location.path('/success').search({
                                                                             'orderId': result.orderId,
                                                                             'type': 'daijia'
                                                                         });

                                   } else {
//                                       alert('下单失败');
                                       alert(result.message);
                                   }

                               }, function (error) {

                                   alert('下单失败');

                               });
                           }

                           /**
                            * 初始化开始输入框
                            *
                            * @param locationInfo
                            */
                           function initBeginInput(locationInfo) {

                               $scope.daijia.beginAddress = locationInfo.name;
                               $scope.daijia.beginAddressDetail = locationInfo.address;
                               $scope.daijia.beginLat = locationInfo.point.lat;
                               $scope.daijia.beginLng = locationInfo.point.lng;
                               
                               if ($scope.daijia.beginLat && $scope.daijia.beginLng) {
                                   calculationFee($scope.daijia.passengerId,
                                                  $scope.daijia.beginLat,
                                                  $scope.daijia.beginLng, $scope.daijia.endLat,
                                                  $scope.daijia.endLng);
                               }

                               //开始地点
                               var stopBeginWatch = null;

                               $scope.beginSelect = function (poi) {

                                   if (!poi.address) {
                                       poi.address = poi.name;
                                   }
                                   $scope.daijia.beginAddress = poi.name;
                                   $scope.daijia.beginAddressDetail = poi.address;
                                   $scope.daijia.beginLat = poi.location.lat;
                                   $scope.daijia.beginLng = poi.location.lng;
                                   $scope.hideBeginTip = true;

                                   if ($scope.daijia.beginLat && $scope.daijia.beginLng) {
                                       calculationFee($scope.daijia.passengerId,
                                                      $scope.daijia.beginLat,
                                                      $scope.daijia.beginLng, $scope.daijia.endLat,
                                                      $scope.daijia.endLng);
                                   }

                               }

                               $scope.stopWatchBeginInput = function () {

                                   if (stopBeginWatch) {
                                       stopBeginWatch();
                                   }
                               }

                               $scope.watchBeginInput = function () {
                                   $scope.hideBeginTip = false;
                                   //开始地点
                                   stopBeginWatch =
                                       $scope.$watch('daijia.beginAddress', function (nv, ov) {
                                           if (nv != ov) {
                                               locationService.placeSearch(nv, locationInfo.city)
                                                   .then(function (resp) {
                                                       if (resp.data.status == 0) {
                                                           $scope.beginPois =
                                                               filterPoi(resp.data.results);
                                                       }
                                                   });
                                           }
                                       });
                               }

                           }

                           /**
                            * 初始化结束输入框
                            *
                            * @param locationInfo
                            */
                           function initEndInput(locationInfo) {

                               //结束地点
                               var stopEndWatch = null;

                               $scope.endSelect = function (poi) {

                                   if (!poi.address) {
                                       poi.address = poi.name;
                                   }

                                   $scope.daijia.endAddress = poi.name;
                                   $scope.daijia.endAddressDetail = poi.address;
                                   $scope.daijia.endLat = poi.location.lat;
                                   $scope.daijia.endLng = poi.location.lng;

                                   $scope.hideEndTip = true;

                                   if ($scope.daijia.beginLat && $scope.daijia.beginLng) {
                                       calculationFee($scope.daijia.passengerId,
                                                      $scope.daijia.beginLat,
                                                      $scope.daijia.beginLng, $scope.daijia.endLat,
                                                      $scope.daijia.endLng);
                                   }
                               }

                               $scope.stopWatchEndInput = function () {
                                   if (stopEndWatch) {
                                       stopEndWatch();
                                   }
                               }
                               $scope.watchEndInput = function () {
                                   $scope.hideEndTip = false;
                                   //开始地点
                                   stopEndWatch =
                                       $scope.$watch('daijia.endAddress', function (nv, ov) {
                                           if (nv != ov) {
                                               locationService.placeSearch(nv, locationInfo.city)
                                                   .then(function (resp) {
                                                       if (resp.data.status == 0) {
                                                           $scope.endPois =
                                                               filterPoi(resp.data.results);
                                                       }
                                                   });
                                           }
                                       });
                               }

                           }

                           /**
                            * 查询附近司机
                            *
                            * @param locationInfo
                            */
                           function coutNearDrivers(locationInfo) {

                               //查询附近司机人数
                               var promise = daijiaService.coutNearDrivers(cfg.sysKey,
                                                                           locationInfo.point.lat,
                                                                           locationInfo.point.lng);

                               promise.then(function (result) {

                                   if (result.count != 0) {
                                       $scope.tip =
                                           $sce.trustAsHtml('<h1>您好，您的附近有<b>' + result.count
                                                            + '</b>名司机</h1><p>最近司机距离您<b>'
                                                            + result.distance + '</b></p>');
                                   } else {
                                       $scope.tip = $sce.trustAsHtml('您的附近暂时没有司机');
                                   }

                               });

                           }

                           var promise = locationService.locateMe($rootScope);

                           promise.then(function (locationInfo) {

                               coutNearDrivers(locationInfo);
                               
                               getAdvs(locationInfo);

                               initBeginInput(locationInfo);

                               initEndInput(locationInfo);

                               //立即预约
                               $scope.submit = function () {
                            	  
                            	   

                                   //验证表单
                                   var params = $scope.daijia;

                                   if (!params.beginAddress || !params.beginLat
                                       || !params.beginLng) {
                                       alert('请先输入并选择预约地址');
                                       return;
                                   }

                                   if (!params.phone) {
                                       alert('请先输入手机号码');
                                       return;
                                   }
                                   if (!(/^0?1\d{10}$/.test(params.phone))) {
                                       alert('请先输入正确的手机号码');
                                       return;
                                   }

                                   //验证手机号是否已经绑定,未绑定发送验证码
                                   var promise = userService.checkBind(cfg.appId, cfg.sysKey,
                                                                       params.phone,
                                                                       $rootScope.openId);

                                   promise.then(function (result) {

                                	   
                                       if (result.isBind) {
                                    	   $("#daijiaButton").attr("disabled",true);
                                           //执行下单逻辑
                                           makeAnAppointment(params.beginAddress,
                                                             params.beginAddressDetail,
                                                             params.beginLat, params.beginLng,
                                                             params.endAddress,
                                                             params.endAddressDetail, params.endLat,
                                                             params.endLng, params.phone, money.toFixed(1));

                                       }
                                       else if (result.isSend) {
                                           //发送验证码,验证验证码
                                           //https://github.com/likeastore/ngDialog
                                           //跳转登录界面
                                           var dialog = ngDialog.open({
                                                                          template: '/assets/v4/partials/validatecode.html',
                                                                          showClose: false,
                                                                          overlay: true,
                                                                          controller: function ($scope,
                                                                                                params) {

                                                                              $scope.phone =
                                                                                  params.phone;

                                                                              $scope.validate =
                                                                                  function () {
                                                                                      //验证信息
                                                                                      if (!$scope.vcode) {
                                                                                          alert(
                                                                                              '请先输入验证码信息');
                                                                                          return;
                                                                                      }

                                                                                      userService.checkCode(
                                                                                          cfg.appId,
                                                                                          cfg.sysKey,
                                                                                          $scope.phone,
                                                                                          $scope.vcode,
                                                                                          $rootScope.openId,
                                                                                          $rootScope.currentLocation.city)
                                                                                          .then(
                                                                                              function (resp) {
                                                                                                  if (resp.success) {
                                                                                                      //验证成功
                                                                                                      dialog.close(
                                                                                                          true);
                                                                                                  } else {
                                                                                                      alert(
                                                                                                          resp.message);
                                                                                                  }

                                                                                              },
                                                                                              function (error) {
                                                                                                  alert(
                                                                                                      '验证失败,请稍后再试');
                                                                                              });
                                                                                  }

                                                                          },
                                                                          resolve: {
                                                                              params: function () {
                                                                                  return $scope.daijia;
                                                                              }
                                                                          }
                                                                      });

                                           dialog.closePromise.then(function (data) {
                                               //执行下单逻辑
                                               if (data.value == true) {
                                                   makeAnAppointment(params.beginAddress,
                                                                     params.beginAddressDetail,
                                                                     params.beginLat,
                                                                     params.beginLng,
                                                                     params.endAddress,
                                                                     params.endAddressDetail,
                                                                     params.endLat, 
                                                                     params.endLng,
                                                                     params.phone, 
                                                                     money);
                                               }
                                           });

                                       } else {
                                           alert('验证码发送失败,请稍后再试');
                                       }
                                   });
                               }

                           }, function (error) {
                               if (error.code == 1) {
                                   alert('没有权限使用地理定位API');
                               } else if (error.code == 2) {
                                   alert('无法确定设备的位置');
                               } else if (error.code == 3) {
                                   alert('定位超时');
                               }
                           });

                       });

//专车
controllers.controller('ZhuanCheCtrl',
                       function ($scope, $rootScope, $routeParams, $sce, $location, gobalService,
                                 locationService,settingService, zhuancheService, userService, ngDialog) {
							ngDialog.closeAll();
                           var cfg = gobalService.config();

                           var i = 0;//优惠券循环下标
                           var couponMoney = 0;//优惠券总金额
                           var nav = angular.element('nav');
                           var areaId = null;//收费规则Id
                           var input_typeId_last = null;
                           var numberAll_last = 0;
                           var travelTime = null;//预算时间
                           var mileage = null;//预算长度
                           var serviceTypeId = null;
                           var serverTime = $("#serverTime").val();
                           var serviceType = $("#serviceType").val();
                           var moneys = null;//预算总金额；
                           var lat = null;//定位精度
                           var lng = null;//定位纬度   
                           var arraynumber = [];
                           var carTypesNew = [];
                           var editNumber = null;//输入数量
                           var numberAll = 0;//选择车辆总数

                           var carTypes2 = '[';
                           var carTypes3 = ''; 

                           if (nav) {
                               nav.show();
                           }
                           angular.element('ul.nav_line > li > a').removeClass('nav_click');
                           angular.element('#zhuanche').addClass('nav_click');

                           $scope.zhuanche = {};

                           $scope.types = function () {
                        	   
                        	   var dialog;
                        	   
                               var promise = zhuancheService.getCarTypesV4(cfg.sysKey,
                                                                           $scope.zhuanche.passengerId,lat,lng);

                               promise.then(function (carTypes) {
                            	   
                                   if (carTypes != null && carTypes.length != 0) {
	                            	   	for (var int = 0; int < carTypes.length; int++) {
	                            		   carTypes[int].arraynumber = arraynumber[int];
	                            	   	}
	                                   	$scope.carTypes = carTypes;
	                                   	
                                   		dialog = ngDialog.open({
                                     	   template: '/assets/v4/partials/types.html',
                                     	   overlay: true,
                                     	   showClose: true,
                                     	   scope: $scope
                                        });
                                   } else {
                                       alert("暂未查询到车型");
                                       $location.path('/zhuanche');
                                   }
                               });
                               $scope.yes = function () {
                            	   dialog.close(true);
                            	   yes("changeCarType");
                               }
                           }
                           
//                           $scope.load = function() {}  
                           
                           
                           if (isFromWx()) {
                               if ($rootScope.openId) {
                                   userService.findWxBind(cfg.sysKey, $rootScope.openId)
                                       .then(function (result) {
                                    	   
                                           if (result.code == 0) {
                                               var bindData = result.data;
                                               $scope.zhuanche.phone = bindData.phone;
                                               $scope.zhuanche.passengerId = bindData.passengerId;

                                               $rootScope.passengerId = bindData.passengerId;
                                               $rootScope.passengerPhone = bindData.phone;
                                               runningZhuanche();
                                        
                                           }
                                       });
                               } else {
                                   $location.path('/index'); //跳转到首页
                               }

                           } 
                           
                           function yes(changeType){
                        	   arraynumber = [];
                               moneys = null;
                               areaId = null;
                               carTypes2 = '[';
                               i = 0;
                               couponMoney = 0;
//                               dialog.close(true);
                               
                               var input_val = 1;
                               var input_typeId = null;
                               var numberAll = 0;
                               
                               if(null!=input_typeId_last && changeType=="changeEndAddres"){
                            	   input_typeId = input_typeId_last;
                            	   numberAll = numberAll_last;
                               }
                               else{
                            	   $(".number").each(function (index, element) {
                                	   arraynumber.push($(this).children("button").attr("class"));
                                	   if($(this).children("button").hasClass("btn-primary")){
                                		   input_val = $(this).children("input").val();
                                		   input_typeId = $(this).children("input").attr("typeId");
                                		   input_typeId_last = input_typeId;
                                		   
                                		   numberAll = $(this).children("button").html();
                                		   numberAll_last = numberAll;
                                	   }
                                   });
                               }
                               
                               if(input_typeId!=null){
                            	   
                            	   /*if($(element).val()!="" && !(/^[1-9]*[0-9][0-9]*$/.test($(element).val())) || ($(element).val() > 10)){
                            		   alert("请输入正确的数量（每种类型最多十辆）");
                            		   return false;
                            	   }
                            	   if($(element).val()==null){
                            		   $(element).val() == "";
                            	   }*/
//                            		   numberAll=Number(numberAll) + Number($(this).children("input").val());
                            		   
                            		   
                                       if($scope.zhuanche.passengerId){
                                    	   $.ajax({
                                               url: "/h5/v4/zhuanche/getPassenger",
                                               type: 'GET',
                                               async: false,
                                               dataType: 'json',
                                               data: {
                                                   "appkey": cfg.sysKey,
                                                   "passengerId": $scope.zhuanche.passengerId
                                               },
                                               success: function (result) {
                                            	   if(result.code==0){
                                            		   if(null!=result.data.passengerGrade && null!=result.data.passengerGrade.passengerGradeAndAreas){
                                                		   angular.forEach(result.data.passengerGrade.passengerGradeAndAreas, function (areasData) {
                                                			   if(input_typeId==areasData.carTypeId){
                                                				   if(serviceType=="tangzu" || serviceType=="tangzuyuyue"){
                                                					   areaId=areasData.tzAreaId;
                                                				   }else if(serviceType=="jieji"){
                                                					   areaId=areasData.jjAreaId;
                                                				   }else if(serviceType=="songji"){
                                                					   areaId=areasData.sjAreaId;
                                                				   }else if(serviceType=="jiezhan"){
                                                					   areaId=areasData.jzAreaId;
                                                				   }else if(serviceType=="songzhan"){
                                                					   areaId=areasData.szAreaId;
                                                				   }else if(serviceType=="rizu"){
                                                					   areaId=areasData.rzAreaId;
                                                				   }else if(serviceType=="banrizu"){
                                                					   areaId=areasData.brzAreaId;
                                                				   }
                                                			   }
                                                			   
                                                		   })
                                            		   }
                                            	   }
                                            	   
                                               }

                                           });
                                       }
                            		   
                                       angular.forEach($scope.carTypes, function (data) {
                                    	   if (data.typeId == input_typeId) {
                                               angular.forEach(data.serverTypes,
                                                               function (result) {
                                                                   if (result.name == serviceType) {
                                                                      
                                                                       carTypes3 +='{"number":' + input_val + ',';
                                                                       carTypes2 +='{"number":' + input_val + ',';
                                                                       editNumber = input_val;
                                                                       
                                                                       if(areaId==null){
                                                                    	   areaId = result.priceId;
                                                                       }
                                                                       /*serviceTypeId = result.typeId;
                                                                       console.debug(serviceTypeId+":::::::::");*/
                                                                       carTypes3 +='"carTypeId":'+ data.typeId + ',';
                                                                       carTypes2 +='"carTypeId":'+ data.typeId + ',';

                                                                       if ($scope.zhuanche.beginLat
                                                                           && $scope.zhuanche.beginLng
                                                                           && areaId) {
                                                                           calculationFee(
                                                                               $scope.zhuanche.passengerId,
                                                                               areaId,
                                                                               $scope.zhuanche.beginLat,
                                                                               $scope.zhuanche.beginLng,
                                                                               $scope.zhuanche.endLat,
                                                                               $scope.zhuanche.endLng);
                                                                       }
                                                                   }

                                                               });
                                           }

                                       });
                               		}
                            	   
                               $("#serlectTypes").html("已选择<span style='color:#FF6000;'>"+numberAll+"</span>1辆");
                           }
                           
                           function runningZhuanche(){
                           	
                               
                               zhuancheService.findZhuanOrder(cfg.sysKey, $scope.zhuanche.passengerId)
                               .then(function (result) {
                                   if (result != null && result.length != 0) {
//			alert("您有未完成的专车订单");
                                       var dialog = ngDialog.open({
                                                                      template: '/assets/v4/partials/notorder.html',
                                                                      overlay: true,
                                                                      showClose: true,
                                                                      scope: $scope
                                                                  });
                                       $scope.into = function () {

                                           var promise = zhuancheService.findOrder(cfg.sysKey,
                                                                                   result[0].id);
                                           
                                           jQuery("#adv").html('');

                                           promise.then(function (fruit) {

                                               if (fruit.success) {
                                                   dialog.close(true);

                                                   var orderInfo = fruit.data;
                                                   var driverId = null;

                                                   $scope.bookTime = orderInfo.serverTime;
                                                   $scope.beginAddress = orderInfo.startAddress;
                                                   $scope.endAddress = orderInfo.endAddress;
                                                   $scope.phone = orderInfo.passengerPhone;

                                                   if (orderInfo.status == 6) { //已经销单
                                                       //跳转到主页
                                                       $location.path('/index');
                                                       $location.replace();
                                                   }
                                                   else if (orderInfo.status == 0
                                                            || orderInfo.status == 1
                                                            || orderInfo.status == 2
                                                            || orderInfo.status == 3
                                                            || orderInfo.status == 4) { //司机已接单

                                                       //跳转到下单成功界面
                                                       /*$location.path('/success').search({
                                                                                             'orderId': orderInfo.id,
                                                                                             'type': 'zhuanche'
                                                                                         });*/
                                                	   $location.path('/execute').search({
                                                           'orderId': orderInfo.id,
                                                           'type': 'zhuanche'
                                                       });

                                                      /* //显示订单信息
                                                       $scope.title = "司机正赶往您的预约地";
                                                       $scope.acceptTime = orderInfo.acceptTime; //接单时间

                                                       if (orderInfo.status == 3) {
                                                           $scope.arriveTime = orderInfo.arriveTime;//到达预约地时间
                                                           $scope.title = "司机已到达预约地";
                                                           $scope.hideArrive = false;
                                                       }

                                                       if (orderInfo.status == 4) {
                                                           $scope.startdriveTime =
                                                               orderInfo.startdriveTime; //出发时间
                                                           $scope.title = "司机正前往目的地";
                                                           $scope.hideStartDrive = false;

                                                           if (orderInfo.treatment) { //跳转支付界面
                                                               $location.path('/payment').search({
                                                                                                     'orderId': orderInfo.id,
                                                                                                     'type': 'zhuanche'
                                                                                                 });
                                                               return;
                                                           }
                                                       }

                                                       //查询司机信息和位置信息
                                                       if (driverId != orderInfo.employId) {
                                                           driverId = orderInfo.employId;
                                                           findDriverInfo(driverId,
                                                                          orderInfo.startLat,
                                                                          orderInfo.startLng);
                                                       }

                                                       setTimeout(runningZhuanche(), 5000);//请求成功间隔一秒再次请求
*/
                                                   }
                                                   else if (orderInfo.status == 5) { //已完成
                                                       //跳转完成界面
                                                       alert('订单已完成');
                                                       $location.path("/index");
                                                   }

                                               }

                                           }, function (error) {
                                               setTimeout(runningZhuanche(), 5000);//请求成功间隔一秒再次请求
                                           });

                                       }

                                   }
                               });
                        }
                           
                           /*$scope.zhuanche.passengerId = 21;
                           $scope.zhuanche.phone = 13880445647;
                           runningZhuanche();*/
                           
                           
                           /**
                            * 查询广告信息
                            */
                           function getAdvs(locationInfo) {
                               var promise = settingService.getAdvs(cfg.sysKey, cfg.ack,
                                                                    locationInfo.point.lat,
                                                                    locationInfo.point.lng,
                                                                    $rootScope.passengerId);
                               promise.then(function (result) {
                                   if (result.code == 0) {
                                       var imgs = result.data;
                                       if (imgs) {
                                           var li = '<div class="main_image"><ul >';

                                           for (var i = 0; i < imgs.length; i++) {
                                               li +=
                                                   '<li><a href="' + imgs[i].linkAddress
                                                   + '"><img src="http://' + result.address + '/'
                                                   + imgs[i].picture + '"/></a></li>'
                                           }

                                           li +='</ul> <a href="javascript:;" id="btn_prev"></a><a href="javascript:;" id="btn_next"></a></div>';

                                           jQuery("#adv").html(li);
                                           //$("#adv").css({"position":"absolute","bottom":'-70px'});
                                           //调用滚动
                                           silder();
                                       }
                                   }
                               });
                           }

                           $scope.tip = $sce.trustAsHtml('<p>正在为您查询附近专车...</p>');
                           $scope.hideBeginTip = true;
                           $scope.hideEndTip = true;

                           $scope.hidePois = function () {
                        	   
                               $scope.hideBeginTip = true;
                               $scope.hideEndTip = true;
                               yes("changeEndAddres");

                           }

                           /**
                            * 过滤不合法的poi
                            *
                            * @param results
                            * @returns {Array.<*>}
                            */
                           function filterPoi(results) {

                               var arr = [];
                               for (var i = 0; i < results.length; i++) {
                                   var poi = results[i];
                                   if (poi.location) {
                                       arr.push(poi);
                                   }
                               }

                               return arr.reverse();
                           }

                           /**
                            * 预算费用
                            *
                            * @param passengerId
                            * @param beginLat
                            * @param beginLng
                            * @param endLat
                            * @param endLng
                            */

                           function calculationFee(passengerId, areaId, beginLat, beginLng, endLat,
                                                   endLng) {

                               $scope.feemsg = $sce.trustAsHtml('正在为您预估费用...');

                               /* var promise = zhuancheService.calculation(cfg.sysKey,areaId,beginLat,beginLng,endLat,endLng);
                                var coupon = zhuancheService.findCoupon(cfg.sysKey,passengerId);
                                promise.then(function(result){
                                });*/
                               var html = '';

                               $.ajax({
                                          url: "/h5/v4/zhuanche/calculationPriceV4",
                                          type: 'GET',
                                          async: false,
                                          dataType: 'json',
                                          data: {
                                              "appkey": cfg.sysKey,
                                              "areaId": areaId,
                                              "startLat": beginLat,
                                              "startLng": beginLng,
                                              "endLat": endLat,
                                              "endLng": endLng
                                          },
                                          success: function (result) {
                                              if (result.success) {
                                                  moneys += result.data.money * editNumber;

                                                  $scope.feeDetail = result.data;
                                                  travelTime = result.data.time;
                                                  mileage = result.data.mileage;
                                                  /*html +='总价约<b style="font-size: 34px;">' + moneys.toFixed(1)
                                                      + '</b>元<img src="/assets/v4/img/wenhao.png" width="24" height="24"/>';*/
                                                  html +='总价约<b style="font-size: 25px;">' + moneys.toFixed(1)
                                                  + '</b>元';
                                                  
                                                  $.ajax({
                                                	  url: "/h5/v4/zhuanche/findCouponV4",
                                                	  type: 'GET',
                                                	  async: false,
                                                	  dataType: 'json',
                                                	  data: {
                                                		  "appkey": cfg.sysKey,
                                                		  "passengerId": $scope.zhuanche.passengerId
                                                	  },
                                                	  success: function (coupons) {
                                                		  if (coupons != null
                                                				  && coupons.length != 0
                                                				  && coupons.length > i) {
                                                			  carTypes2 +=
                                                				  '"couponIds":"'
                                                				  + coupons[i].id+'",';
                                                			  couponMoney +=coupons[i].couponRule.money!= null? coupons[i].couponRule.money: result.data.money* coupons[i].couponRule.discount / 10;
                                                				  /*var couponType = coupons[i].couponRule.money!= null ? '优惠券抵扣'+ coupons[i].couponRule.money
                                            							  	  + '元' : '优惠券折扣'
                                            								  + coupons[i].couponRule.discount
                                            								  + '折';
                                                				  html +='<span style="font-size:18px;color:#adadad;float: right;margin-top:10px;">'+couponType+'</span>';*/
                                                							  i++;
                                                							  $scope.feemsg =
                                                								  $sce.trustAsHtml(html);
                                                		  } else {
                                                			  carTypes2 += '"couponIds":"",';
                                                		  }
                                                	  }
                                                  });
                                                  carTypes2 +=
                                                      '"budgetPay":' + result.data.money
                                                      + ',"startPrice":' + result.data.startPrice
                                                      + ',"mileagePrice":' + result.data.mileagePrice
                                                      + ',"travelTimePrice":'
                                                      + result.data.travelTimePrice + ',"areaId":'
                                                      + areaId + '}';
                                                  $scope.feemsg = $sce.trustAsHtml(html);
                                              } else {
                                                  $scope.feeDetail = null;
                                                  $scope.feemsg = $sce.trustAsHtml('未能为您预估费用.');
                                              }

                                          }

                                      });
                           }

                           $scope.showFeeDetail = function () {

                               if ($scope.feeDetail) {

                                   if ($scope.feeDetail.pay_detail) {
                                       $scope.feeDetail.detail =
                                           $sce.trustAsHtml(
                                               $scope.feeDetail.pay_detail.replace(/\n/g, "<br/>"));
                                   }
                                   //弹出支付提示
                                   ngDialog.open({
                                                     template: '/assets/v4/partials/feeInfo.html',
                                                     overlay: true,
                                                     showClose: true,
                                                     scope: $scope
                                                 });

                               }
                           }

                           /**
                            * 预约专车订单
                            *
                            * @param beginAddress
                            * @param beginAddressDetail
                            * @param beginLat
                            * @param beginLng
                            * @param endAddress
                            * @param endAddressDetail
                            * @param endLat
                            * @param endLng
                            * @param phone
                            * @param carTypeId
                            */
                           function makeAnAppointment(passengerId, passengerPhone, serverTime,
                                                      startAddress, startAddressDetail, startLat,
                                                      startLng,
                                                      endAddress, endAddressDetail, endLat, endLng,
                                                      travelTime, mileage, flightNo, trainNo,
                                                      serviceTypeId, serviceType, carTypes2, couponMoney) {

//    	carTypes2 +=',"number":'+$scope.zhuanche.number+'}]';
                               carTypes2 += ']';
                               var promise = zhuancheService.makeAnAppointment(cfg.sysKey, cfg.ack,
                                                                               lat, lng,
                                                                               $rootScope.openId,
                                                                               passengerId,
                                                                               passengerPhone,
                                                                               serverTime,
                                                                               startAddress,
                                                                               startAddressDetail,
                                                                               startLat, startLng,
                                                                               endAddress,
                                                                               endAddressDetail,
                                                                               endLat, endLng,
                                                                               travelTime, mileage,
                                                                               flightNo, trainNo,
                                                                               serviceTypeId, serviceType,
                                                                               carTypes2,
                                                                               couponMoney);

                               promise.then(function (result) {
                                   if (result.code == 0) {
                                       var orderIds;
                                       if (result.data.orderIds) {
                                           orderIds = result.data.orderIds;
                                           $(".main_image").hide();
                                           $location.path('/success').search({
                                                                                 'orderId': orderIds.split(",")[0],
                                                                                 'type': 'zhuanche'
                                                                             });
                                       } /*else if (result.data.orderGroupId) {
                                           zhuancheService.findGroupV4(cfg.sysKey,
                                                                       result.data.orderGroupId)
                                               .then(function (data) {
                                                   if (data != null) {
                                                       orderId = data[0].id;
                                                       $location.path('/success').search({
                                                                                             'orderId': orderId,
                                                                                             'type': 'zhuanche'
                                                                                         });
                                                   }

                                               });
                                       }
*/
                                   } else {
                                       alert(result.message);
                                   }

                               }, function (error) {

                                   alert('下单失败');

                               });
                           }

                           //选择列表开关
                           $scope.hideCarTypeList = true;

                           $scope.showSelect = function () {
                               $scope.hideCarTypeList = false;
                           }

                           /**
                            * 选择专车
                            *
                            * @param carType
                            */
                           /*  $scope.selectCarType = function(carType){
                            $scope.zhuanche.carType = carType;
                            console.debug($scope.zhuanche.carType)
                            $scope.hideCarTypeList = true;

                            angular.forEach($scope.zhuanche.carType.serverTypes, function(data){
                            if(data.name == serviceType){
                            areaId = data.priceId;
                            serviceTypeId = data.typeId;
                            carTypes2 = '';
                            carTypes2 +='[{"carTypeId":'+$scope.zhuanche.carType.typeId+',"areaId":'+data.priceId;
                            carTypes3 = carTypes2;
                            }
                            });
                            //查询附近司机
                            countNearCars($rootScope.currentLocation.point.lat,$rootScope.currentLocation.point.lng,$scope.zhuanche.carType.typeId);
                            //重新预算价格
                            if($scope.zhuanche.beginLat && $scope.zhuanche.beginLng && $scope.zhuanche.endLat && $scope.zhuanche.endLng && $scope.zhuanche.carType){
                            console.log(areaId);
                            calculationFee($scope.zhuanche.passengerId,areaId,$scope.zhuanche.beginLat,$scope.zhuanche.beginLng,$scope.zhuanche.endLat,$scope.zhuanche.endLng);
                            }
                            }*/

                           /**
                            * 根据车辆类型与位置查询附近车辆人数
                            *
                            * @param lat
                            * @param lng
                            * @param carTypeId
                            */
                           function countNearCars(lat, lng, carTypeId) {

                               //查询附近司机人数
                               var promise = zhuancheService.coutNearDrivers(cfg.sysKey, lat, lng,
                                                                             carTypeId);

                               promise.then(function (result) {

                                   if (result.count != 0) {
                                       $scope.tip =
                                           $sce.trustAsHtml('<h1>您好，您的附近有<b>' + result.count
                                                            + '</b>辆专车</h1><p>最近专车距离您<b>'
                                                            + result.distance + '</b></p>');
                                   } else {
                                       $scope.tip = $sce.trustAsHtml('您的附近暂时没有专车');
                                   }

                               });

                           }
                           
                           /**
                            * 初始化开始地址选择框
                            *
                            * @param locationInfo
                            */
                           function initBeginInput(locationInfo) {

                               
                               lat = locationInfo.point.lat;
                               lng = locationInfo.point.lng;
                               
                               if($("#serviceType").val()=="jieji"){
                        		   locationService.placeAirportSearch("机场", locationInfo.city)
                                   .then(function (resp) {
                                       if (resp.data.status == 0) {
                                           $scope.zhuanche.beginAddress = filterPoi(resp.data.results)[0].name;
                                           $scope.zhuanche.beginAddressDetail = filterPoi(resp.data.results)[0].address;
                                           $scope.zhuanche.beginLat = filterPoi(resp.data.results)[0].location.lat;
                                           $scope.zhuanche.beginLng = filterPoi(resp.data.results)[0].location.lng;
                                       }
                                   });
                        		   
                        	   }else if($("#serviceType").val()=="jiezhan"){
                        		   locationService.placeStationSearch("火车站", locationInfo.city)
                                   .then(function (resp) {
                                       if (resp.data.status == 0) {
                                           $scope.zhuanche.beginAddress = filterPoi(resp.data.results)[0].name;
                                           $scope.zhuanche.beginAddressDetail = filterPoi(resp.data.results)[0].address;
                                           $scope.zhuanche.beginLat = filterPoi(resp.data.results)[0].location.lat;
                                           $scope.zhuanche.beginLng = filterPoi(resp.data.results)[0].location.lng;
                                       }
                                   });
                        		   
                        	   }else{
                        		   $scope.zhuanche.beginAddress = locationInfo.name;
                                   $scope.zhuanche.beginAddressDetail = locationInfo.address;
                                   $scope.zhuanche.beginLat = locationInfo.point.lat;
                                   $scope.zhuanche.beginLng = locationInfo.point.lng;
                        	   }
                               
                               
                               
                               

                               //开始地点
                               var stopBeginWatch = null;

                               $scope.beginSelect = function (poi) {

                                   if (!poi.address) {
                                       poi.address = poi.name;
                                   }

                                   $scope.zhuanche.beginAddress = poi.name;
                                   $scope.zhuanche.beginAddressDetail = poi.address;
                                   $scope.zhuanche.beginLat = poi.location.lat;
                                   $scope.zhuanche.beginLng = poi.location.lng;
                                   
                                   
                                   
                                   
                                   
                                   
                                   
                                   /*if ($scope.zhuanche.beginLat
                                           && $scope.zhuanche.beginLng
                                           && $scope.zhuanche.endLat
                                           && $scope.zhuanche.endLng
                                           && areaId) {
                                    	   console.debug(i);
                                    	   moneys = null;
                                    	   carTypes2 = '['+carTypes3;
                                           calculationFee(
                                        		   
                                               $scope.zhuanche.passengerId,
                                               areaId,
                                               $scope.zhuanche.beginLat,
                                               $scope.zhuanche.beginLng,
                                               $scope.zhuanche.endLat,
                                               $scope.zhuanche.endLng);
                                       }*/

                                   /*moneys = null;
                                   carTypes2 = '[';
                                   i = 0;
                                   couponMoney = 0;
                                   $(".number").each(function (index, element) {
                                       if ($.trim($(element).val())) {

                                           angular.forEach($scope.carTypes, function (data) {
                                               if (data.typeId == $(element).attr("typeId")) {
                                                   angular.forEach(data.serverTypes,
                                                                   function (result) {

                                                                       if (result.name
                                                                           == serviceType) {
                                                                           if (index >= 1) {
                                                                               carTypes2 +=
                                                                                   ',{"number":'
                                                                                   + $(element)
                                                                                       .val() + ',';
                                                                           } else {
                                                                               carTypes2 +=
                                                                                   '{"number":' + $(
                                                                                       element)
                                                                                       .val() + ',';
                                                                           }
                                                                           areaId = result.priceId;
                                                                           serviceTypeId =
                                                                               result.typeId;
                                                                           carTypes2 +=
                                                                               '"carTypeId":'
                                                                               + data.typeId + ',';

                                                                           if ($scope.zhuanche.beginLat
                                                                               && $scope.zhuanche.beginLng
                                                                               && $scope.zhuanche.endLat
                                                                               && $scope.zhuanche.endLng
                                                                               && areaId) {
                                                                        	   console.debug(i);
                                                                               calculationFee(
                                                                                   $scope.zhuanche.passengerId,
                                                                                   areaId,
                                                                                   $scope.zhuanche.beginLat,
                                                                                   $scope.zhuanche.beginLng,
                                                                                   $scope.zhuanche.endLat,
                                                                                   $scope.zhuanche.endLng);
                                                                           }
                                                                       }

                                                                   });
                                               }

                                           });
                                       }
                                   });*/

                               }

                               $scope.stopWatchBeginInput = function () {

                                   if (stopBeginWatch) {
                                       stopBeginWatch();
                                   }
                               }

                               $scope.watchBeginInput = function () {
                                   $scope.hideBeginTip = false;
                                   //开始地点
                                   stopBeginWatch =
                                       $scope.$watch('zhuanche.beginAddress', function (nv, ov) {
                                           if (nv != ov) {
                                               if($("#serviceType").val()=="jieji"){
                                        		   locationService.placeAirportSearch(nv, locationInfo.city)
                                                   .then(function (resp) {
                                                       if (resp.data.status == 0) {
                                                           $scope.beginPois =
                                                               filterPoi(resp.data.results);
                                                       }
                                                   });
                                        		   
                                        	   }else if($("#serviceType").val()=="jiezhan"){
                                        		   locationService.placeStationSearch(nv, locationInfo.city)
                                                   .then(function (resp) {
                                                       if (resp.data.status == 0) {
                                                           $scope.beginPois =
                                                               filterPoi(resp.data.results);
                                                       }
                                                   });
                                        		   
                                        	   }else{
                                        		   locationService.placeSearch(nv, locationInfo.city)
                                                   .then(function (resp) {
                                                       if (resp.data.status == 0) {
                                                           $scope.beginPois = filterPoi(resp.data.results);
                                                       }
                                                   });
                                        	   }
                                           }
                                       });
                               }
                           }

                           function initEndInput(locationInfo) {
                               //结束地点
                               var stopEndWatch = null;

                               $scope.endSelect = function (poi) {

                                   if (!poi.address) {
                                       poi.address = poi.name;
                                   }

                                   $scope.zhuanche.endAddress = poi.name;
                                   $scope.zhuanche.endAddressDetail = poi.address;
                                   $scope.zhuanche.endLat = poi.location.lat;
                                   $scope.zhuanche.endLng = poi.location.lng;
                                   
                                   /*if ($scope.zhuanche.beginLat
                                           && $scope.zhuanche.beginLng
                                           && $scope.zhuanche.endLat
                                           && $scope.zhuanche.endLng
                                           && areaId) {
                                	   		moneys = null;
                                	   		carTypes2 = '['+carTypes3;
                                           calculationFee(
                                               $scope.zhuanche.passengerId,
                                               areaId,
                                               $scope.zhuanche.beginLat,
                                               $scope.zhuanche.beginLng,
                                               $scope.zhuanche.endLat,
                                               $scope.zhuanche.endLng);
                                       }*/
                                   /*
                                   carTypes2 = '[';
                                   i = 0;
                                   couponMoney = 0;
                                   $(".number").each(function (index, element) {
                                       if ($.trim($(element).val())) {

                                           angular.forEach($scope.carTypes, function (data) {
                                               if (data.typeId == $(element).attr("typeId")) {
                                                   angular.forEach(data.serverTypes,
                                                                   function (result) {

                                                                       if (result.name
                                                                           == serviceType) {
                                                                           if (index >= 1) {
                                                                               carTypes2 +=
                                                                                   ',{"number":'
                                                                                   + $(element)
                                                                                       .val() + ',';
                                                                           } else {
                                                                               carTypes2 +=
                                                                                   '{"number":' + $(
                                                                                       element)
                                                                                       .val() + ',';
                                                                           }
                                                                           areaId = result.priceId;
                                                                           serviceTypeId =
                                                                               result.typeId;
                                                                           carTypes2 +=
                                                                               '"carTypeId":'
                                                                               + data.typeId + ',';

                                                                           console.debug("typeId:"
                                                                                         + data.typeId);
                                                                           if ($scope.zhuanche.beginLat
                                                                               && $scope.zhuanche.beginLng
                                                                               && $scope.zhuanche.endLat
                                                                               && $scope.zhuanche.endLng
                                                                               && areaId) {
                                                                               calculationFee(
                                                                                   $scope.zhuanche.passengerId,
                                                                                   areaId,
                                                                                   $scope.zhuanche.beginLat,
                                                                                   $scope.zhuanche.beginLng,
                                                                                   $scope.zhuanche.endLat,
                                                                                   $scope.zhuanche.endLng);
                                                                           }
                                                                       }

                                                                   });
                                               }

                                           });
                                       }
                                   });*/

                               }

                               $scope.stopWatchEndInput = function () {

                                   if (stopEndWatch) {
                                       stopEndWatch();
                                   }
                               }
                               $scope.watchEndInput = function () {
                                   $scope.hideEndTip = false;
                                   //结束地点
                                   stopEndWatch =
                                       $scope.$watch('zhuanche.endAddress', function (nv, ov) {
                                           if (nv != ov) {
                                        	   if($("#serviceType").val()=="songji"){
                                        		   locationService.placeAirportSearch(nv, locationInfo.city)
                                                   .then(function (resp) {
                                                       if (resp.data.status == 0) {
                                                           $scope.endPois =
                                                               filterPoi(resp.data.results);
                                                       }
                                                   });
                                        		   
                                        	   }else if($("#serviceType").val()=="songzhan"){
                                        		   locationService.placeStationSearch(nv, locationInfo.city)
                                                   .then(function (resp) {
                                                       if (resp.data.status == 0) {
                                                           $scope.endPois =
                                                               filterPoi(resp.data.results);
                                                       }
                                                   });
                                        		   
                                        	   }else{
                                        		   locationService.placeSearch(nv, locationInfo.city)
                                                   .then(function (resp) {
                                                       if (resp.data.status == 0) {
                                                           $scope.endPois =
                                                               filterPoi(resp.data.results);
                                                       }
                                                   });
                                        		   
                                        	   }
                                               
                                           }
                                       });
                               }
                           }

                           var promise = locationService.locateMe($rootScope);

                           promise.then(function (locationInfo) {
                               lat = locationInfo.point.lat;
                               lng = locationInfo.point.lng;

                               //查询车辆类型
                               var promise = zhuancheService.getCarTypesV4(cfg.sysKey,
                                                                           $scope.zhuanche.passengerId,lat,lng);

                               promise.then(function (carTypes) {
                                   $scope.carTypes = carTypes;
                                   if (carTypes!=null && carTypes.length > 0) {
                                       $scope.zhuanche.carType = carTypes[0];

                                       //查询附近司机
                                       countNearCars(locationInfo.point.lat, locationInfo.point.lng,
                                                     $scope.zhuanche.carType.typeId);
                                   } else {
                                       $scope.tip = $sce.trustAsHtml('您的附近暂时没有专车');
                                   }

                                   //初始化化开始选择框
                                   initBeginInput(locationInfo);
                                   
                                   //获取广告
                                   getAdvs(locationInfo);

                                   //初始化结束选择框
                                   initEndInput(locationInfo);
                               });

                               //立即预约
                               $scope.submit = function () {
                            	   
                            	   
                            	   
                            	   
                            	   
                            	   
                            	   
                            	   
                            	   if ($("#serviceType").val() == "tangzu") {
                                       serviceType = $("#serviceType").val();
                                       serverTime = $("#serverTime").val();
                                   } else if ($("#serviceType").val() == "tangzuyuyue") {
                                       serviceType = "tangzu";
                                       serverTime = $scope.zhuanche.serverTime;
                                   } else {
                                       serviceType = $("#serviceType").val();
                                       serverTime = $scope.zhuanche.serverTime;
                                   }
                            	   
                            	   

                                   //验证表单
                                   var params = $scope.zhuanche;

                                   if (!params.beginAddress || !params.beginLat
                                       || !params.beginLng) {
                                       alert('请先输入并选择预约地址');
                                       return;
                                   }

                                   if (!params.phone) {
                                       alert('请先输入手机号码');
                                       return;
                                   }

                                   if (!(/^0?1\d{10}$/.test(params.phone))) {
                                       alert('请先输入正确的手机号码');
                                       return;
                                   }
                                   if($("#serviceType").val()=="jiezhan" || $("#serviceType").val()=="songzhan"){
                                	   if (!params.trainNo) {
                                           alert('请先输入班次号');
                                           return;
                                       }

                                       if ((/[\u4E00-\u9FA5]/.test(params.trainNo))) {
                                           alert('请先输入正确的班次号');
                                           return;
                                       }
                                   }
                                   if($("#serviceType").val()=="jieji" || $("#serviceType").val()=="songji"){
                                	   if (!params.flightNo) {
                                           alert('请先输入航班号');
                                           return;
                                       }

                                       if ((/[\u4E00-\u9FA5]/.test(params.flightNo))) {
                                           alert('请先输入正确的航班号');
                                           return;
                                       }
                                   }
                                   
                                   if(!serverTime){
                                	   alert('请先输入预约时间');
                                       return;
                                   }
                                   var d=new Date();
                            	   var t=d.getTime();
                            	   t= t - 1800000;
                            	   d=new Date(t);
                                   
                                   if(serverTime < d.Format("yyyy-MM-dd hh:mm")){
                            		   alert('预约时间不能在现在时间之前');
                                       return;
                            	   }

                                   if (carTypes2 == "[") {
                                       alert('请选择预约车型');
                                       return;
                                   }
                                   console.debug(carTypes2);

                                   //验证手机号是否已经绑定,未绑定发送验证码
                                   var promise = userService.checkBind(cfg.appId, cfg.sysKey,
                                                                       params.phone,
                                                                       $rootScope.openId);

                                   promise.then(function (result) {
                                       if (result.isBind) {
                                    	   $("#zhuancheButton").attr("disabled",true);
                                           //执行下单逻辑
                                           makeAnAppointment($scope.zhuanche.passengerId,
                                                             $scope.zhuanche.phone, serverTime,
                                                             $scope.zhuanche.beginAddress,
                                                             $scope.zhuanche.beginAddressDetail,
                                                             $scope.zhuanche.beginLat,
                                                             $scope.zhuanche.beginLng,
                                                             $scope.zhuanche.endAddress,
                                                             $scope.zhuanche.endAddressDetail,
                                                             $scope.zhuanche.endLat,
                                                             $scope.zhuanche.endLng, travelTime,
                                                             mileage, $scope.zhuanche.flightNo,
                                                             $scope.zhuanche.trainNo, serviceTypeId, serviceType,
                                                             carTypes2, couponMoney);

                                       }
                                       else if (result.isSend) {
                                           //发送验证码,验证验证码
                                           //跳转登录界面
                                           var dialog = ngDialog.open({
                                                                          template: '/assets/v4/partials/validatecode.html',
                                                                          showClose: false,
                                                                          overlay: true,
                                                                          controller: function ($scope,
                                                                                                params) {

                                                                              $scope.phone =
                                                                                  params.phone;

                                                                              $scope.validate =
                                                                                  function () {
                                                                                      //验证信息
                                                                                      if (!$scope.vcode) {
                                                                                          alert(
                                                                                              '请先输入验证码信息');
                                                                                          return;
                                                                                      }

                                                                                      userService.checkCode(
                                                                                          cfg.appId,
                                                                                          cfg.sysKey,
                                                                                          $scope.phone,
                                                                                          $scope.vcode,
                                                                                          $rootScope.openId,
                                                                                          $rootScope.currentLocation.city)
                                                                                          .then(
                                                                                              function (resp) {
                                                                                                  if (resp.success) {
                                                                                                      //验证成功
                                                                                                      dialog.close(
                                                                                                          true);
                                                                                                  } else {
                                                                                                      alert(
                                                                                                          resp.message);
                                                                                                  }

                                                                                              },
                                                                                              function (error) {
                                                                                                  alert(
                                                                                                      '验证失败,请稍后再试');
                                                                                              });
                                                                                  }

                                                                          },
                                                                          resolve: {
                                                                              params: function () {
                                                                                  return $scope.zhuanche;
                                                                              }
                                                                          }
                                                                      });

                                           dialog.closePromise.then(function (data) {
                                               //执行下单逻辑
                                               if (data.value == true) {

                                                   makeAnAppointment(params.passengerId,
                                                                     params.phone, serverTime,
                                                                     params.beginAddress,
                                                                     params.beginAddressDetail,
                                                                     params.beginLat,
                                                                     params.beginLng,
                                                                     params.endAddress,
                                                                     params.endAddressDetail,
                                                                     params.endLat, params.endLng,
                                                                     travelTime, mileage,
                                                                     params.flightNo,
                                                                     params.trainNo, serviceTypeId, serviceType,
                                                                     carTypes2, couponMoney);
                                               }
                                           });

                                       } else {
                                           alert('验证码发送失败,请稍后再试');
                                       }
                                   });
                               }

                           }, function (error) {
                               if (error.code == 1) {
                                   alert('没有权限使用地理定位API');
                               } else if (error.code == 2) {
                                   alert('无法确定设备的位置');
                               } else if (error.code == 3) {
                                   alert('定位超时');
                               }
                           });
                           
                           setTimeout(function(){
                        	   
                        	   var promise = zhuancheService.getCarTypesV4(cfg.sysKey,$scope.zhuanche.passengerId,lat,lng);
                        	   promise.then(function (carTypes) {
                         	   if (carTypes != null && carTypes.length != 0) {
                         		   for (var int = 0; int < carTypes.length; int++) {
                         			   carTypes[int].arraynumber = arraynumber[int];
                         		   }
                         		   $scope.carTypes = carTypes;
                         		   
                         		   if($scope.carTypes&&$scope.carTypes.length>0){
                         			   
                                 	   arraynumber = [];
                                        moneys = null;
                                        areaId = null;
                                        carTypes2 = '[';
                                        i = 0;
                                        couponMoney = 0;
//                                            dialog.close(true);
                                        
                                        var input_val = 1;
                                        var input_typeId = null;
                                        var numberAll = 0;
                                        
                                        input_val = 1;
                             		   input_typeId = $scope.carTypes[0].typeId;
                             		   input_typeId_last = input_typeId;
                             		   
                             		   numberAll = $scope.carTypes[0].typeName;
                             		   numberAll_last = numberAll;
                             		   
                                 		   if($scope.zhuanche.passengerId){
                                         	   $.ajax({
                                                    url: "/h5/v4/zhuanche/getPassenger",
                                                    type: 'GET',
                                                    async: false,
                                                    dataType: 'json',
                                                    data: {
                                                        "appkey": cfg.sysKey,
                                                        "passengerId": $scope.zhuanche.passengerId
                                                    },
                                                    success: function (result) {
                                                 	   if(result.code==0){
                                                 		   if(null!=result.data.passengerGrade && null!=result.data.passengerGrade.passengerGradeAndAreas){
                                                     		   angular.forEach(result.data.passengerGrade.passengerGradeAndAreas, function (areasData) {
                                                     			   if(input_typeId==areasData.carTypeId){
                                                     				   if(serviceType=="tangzu" || serviceType=="tangzuyuyue"){
                                                     					   areaId=areasData.tzAreaId;
                                                     				   }else if(serviceType=="jieji"){
                                                     					   areaId=areasData.jjAreaId;
                                                     				   }else if(serviceType=="songji"){
                                                     					   areaId=areasData.sjAreaId;
                                                     				   }else if(serviceType=="jiezhan"){
                                                     					   areaId=areasData.jzAreaId;
                                                     				   }else if(serviceType=="songzhan"){
                                                     					   areaId=areasData.szAreaId;
                                                     				   }else if(serviceType=="rizu"){
                                                     					   areaId=areasData.rzAreaId;
                                                     				   }else if(serviceType=="banrizu"){
                                                     					   areaId=areasData.brzAreaId;
                                                     				   }
                                                     			   }
                                                     			   
                                                     		   })
                                                 		   }
                                                 	   }
                                                 	   
                                                    }

                                                });
                                            }
                                 		   
                                 		   angular.forEach($scope.carTypes, function (data) {
                                         	   if (data.typeId == input_typeId) {
                                                    angular.forEach(data.serverTypes,
                                                                    function (result) {
                                                                        if (result.name == serviceType) {
                                                                           
                                                                            carTypes3 +='{"number":' + input_val + ',';
                                                                            carTypes2 +='{"number":' + input_val + ',';
                                                                            editNumber = input_val;
                                                                            
                                                                            if(areaId==null){
                                                                         	   areaId = result.priceId;
                                                                            }
                                                                            /*serviceTypeId = result.typeId;
                                                                            console.debug(serviceTypeId+":::::::::");*/
                                                                            carTypes3 +='"carTypeId":'+ data.typeId + ',';
                                                                            carTypes2 +='"carTypeId":'+ data.typeId + ',';

                                                                            if ($scope.zhuanche.beginLat
                                                                                && $scope.zhuanche.beginLng
                                                                                && areaId) {
                                                                                calculationFee(
                                                                                    $scope.zhuanche.passengerId,
                                                                                    areaId,
                                                                                    $scope.zhuanche.beginLat,
                                                                                    $scope.zhuanche.beginLng,
                                                                                    $scope.zhuanche.endLat,
                                                                                    $scope.zhuanche.endLng);
                                                                            }
                                                                        }

                                                                    });
                                                }

                                            });
                                 		   $("#serlectTypes").html("已选择<span style='color:#FF6000;'>"+numberAll+"</span>1辆");
                                    }
                         	   }
                            });
                        	   
                           },1500);
                           
                       });

//跑腿取送控制器
controllers.controller('PaotuiCtrl',
                       function ($scope, $rootScope, $sce, $uibModal, $filter, $location,
                                 gobalService,settingService, paotuiService, locationService, userService,
                                 ngDialog) {
	
							ngDialog.closeAll();

                           var cfg = gobalService.config();

                           var nav = angular.element('nav');

                           if (nav) {
                               nav.show();
                           }
                           angular.element('ul.nav_line > li > a').removeClass('nav_click');
                           angular.element('#paotui').addClass('nav_click');

                           $scope.hideTypeList = true;

                           $scope.task = {};

                           $scope.endAddressHit = "请输入任务终点";
                           
                          

                           if (isFromWx()) {
                               if ($rootScope.openId) {
                                   userService.findWxBind(cfg.sysKey, $rootScope.openId)
                                       .then(function (result) {
                                           if (result.code == 0) {
                                               var bindData = result.data;
                                               $scope.task.phone = bindData.phone;
                                               $scope.task.passengerId = bindData.passengerId;

                                               $rootScope.passengerId = bindData.passengerId;
                                               $rootScope.passengerPhone = bindData.phone;
                                               
                                               runningPaotui();
                                         
                                           }
                                       });
                               } else {
                                   $location.path('/index'); //跳转到首页
                               }

                           } 

                           function runningPaotui(){    
                               paotuiService.findErrandOrder(cfg.sysKey, $scope.task.passengerId)
                               .then(function (result) {
                                   if (result != null && result.length != 0) {
//			alert("您有未完成的跑腿订单");
                                       var dialog = ngDialog.open({
                                                                      template: '/assets/v4/partials/notorder.html',
                                                                      overlay: true,
                                                                      showClose: true,
                                                                      scope: $scope
                                                                  });

                                       $scope.into = function () {
                                           var promise = paotuiService.findOrder(cfg.sysKey,
                                                                                 result[0].id);

                                           promise.then(function (fruit) {

                                               if (fruit) {
                                                   dialog.close(true);
                                                   var orderInfo = fruit;

                                                   $scope.bookTime = orderInfo.startTime;
                                                   $scope.beginAddress = orderInfo.startAddress;
                                                   $scope.endAddress = orderInfo.deliverAddress;
                                                   $scope.phone = orderInfo.passengerPhone;

                                                   if (orderInfo.status == 5 || orderInfo.status
                                                                                == 4) { //已经销单
                                                       //跳转到主页
                                                       if (orderInfo.status == 4) {
                                                           alert("订单已完成");
                                                       } else if (orderInfo.status == 5) {
                                                           alert("您已被销单");
                                                       }

                                                       $location.path('/index');
                                                       $location.replace();
                                                   }
                                                   else if (orderInfo.status == 0
                                                            || orderInfo.status == 1
                                                            || orderInfo.status == 2
                                                            || orderInfo.status == 3) { //司机已接单

                                                	   
                                                	 //跳转接单界面
                                                       $location.path('/execute').search({
                                                                                             'orderId': orderInfo.id,
                                                                                             'type': 'paotui'
                                                                                         });
                                                	   
                                                      /* if (orderInfo.status == 3
                                                           && orderInfo.treatment) { //司机已经确认支付信息
                                                           //跳转到支付界面
                                                           $location.path('/payment').search({
                                                                                                 'orderId': orderInfo.id,
                                                                                                 'type': 'paotui'
                                                                                             });
                                                           return;
                                                       }

                                                       

                                                       //跳转到下单成功界面
                                                       $location.path('/success').search({
                                                                                             'orderId': orderInfo.id,
                                                                                             'type': 'paotui'
                                                                                         });
                                                       setTimeout(runningPaotui(), 5000);//请求成功间隔5秒再次请求
*/				
                                                   }
                                                   else if (orderInfo.status == 5) { //已完成
                                                       //跳转完成界面
                                                       alert('订单已完成');
                                                       $location.path("/index");
                                                   }

                                               }

                                           }, function (error) {
                                               setTimeout(runningPaotui(), 5000);//请求成功间隔5秒再次请求
                                           });

                                       }

                                   }
                               });
                         } 
                           
                               /*$scope.task.passengerId = 21;
                               $scope.task.phone = 13880445647;
                               runningPaotui();*/
                           
                           
                           /**
                            * 查询广告信息
                            */
                           function getAdvs(locationInfo) {
                               var promise = settingService.getAdvs(cfg.sysKey, cfg.ack,
                                                                    locationInfo.point.lat,
                                                                    locationInfo.point.lng,
                                                                    $rootScope.passengerId);
                               promise.then(function (result) {
                                   if (result.code == 0) {
                                       var imgs = result.data;
                                       if (imgs) {
                                           var li = '<div class="main_image"><ul >';

                                           for (var i = 0; i < imgs.length; i++) {
                                               li +=
                                                   '<li><a href="' + imgs[i].linkAddress
                                                   + '"><img src="http://' + result.address + '/'
                                                   + imgs[i].picture + '"/></a></li>'
                                           }

                                           li +=
                                               '</ul> <a href="javascript:;" id="btn_prev"></a><a href="javascript:;" id="btn_next"></a></div>';

                                           jQuery("#adv").html(li);
                                           //调用滚动
                                           silder();
                                       }
                                   }
                               });
                           }

                           $scope.tip = $sce.trustAsHtml('<p>正在为您查询附近服务人员...</p>');
                           $scope.hideBeginTip = true;
                           $scope.hideEndTip = true;

                           $scope.hidePois = function () {
                               $scope.hideBeginTip = true;
                               $scope.hideEndTip = true;
                           }

                           $scope.showSelect = function () {
                               $scope.hideTypeList = false;
                           }

                           /**
                            * 选择类型
                            * @param type
                            */
                           $scope.selectType = function (type) {
                               $scope.task.type = type;
                               $scope.hideTypeList = true;
                               if ($scope.task.beginLat && $scope.task.beginLng
                                       && $scope.task.type) {
                                       calculationFee($scope.task.type.areaId, $scope.task.beginLat,
                                                      $scope.task.beginLng, $scope.task.endLat,
                                                      $scope.task.endLng);
                                   }

                               $scope.endAddressHit =
                                   type.endHint + (type.endAddress ? "" : "(选填)");

                           }
                           /**
                            * 查询附近有多少服务人员
                            *
                            * @param lat
                            * @param lng
                            */
                           function countNearEmploys(lat, lng, companyId) {

                               //查询附近司机人数
                               var promise = paotuiService.countNearEmploys(cfg.sysKey, lat, lng,
                                                                            companyId);

                               promise.then(function (result) {

                                   if (result.count != 0) {
                                       $scope.tip =
                                           $sce.trustAsHtml('<h1>您好，您的附近有<b>' + result.count
                                                            + '</b>位服务人员</h1><p>最近的服务人员距离您<b>'
                                                            + result.distance + '</b></p>');
                                   } else {
                                       $scope.tip = $sce.trustAsHtml('您的附近暂时没有服务人员');
                                   }

                               });

                           }

                           /**
                            * 预算费用
                            *
                            * @param areaId
                            * @param beginLat
                            * @param beginLng
                            * @param endLat
                            * @param endLng
                            */
                           function calculationFee(areaId, beginLat, beginLng, endLat, endLng) {
                               $scope.feemsg = $sce.trustAsHtml('正在为您预估费用...');

                               var promise = paotuiService.calculation(cfg.sysKey, areaId, beginLat,
                                                                       beginLng, endLat, endLng);
                               promise.then(function (result) {

                                   if (result) {
                                       $scope.feeDetail = result;
                                       $scope.feemsg =
                                           $sce.trustAsHtml(
                                               '约<b style="font-size: 25px;">' + result.money.toFixed(1)
                                               + '</b>元<img src="/assets/v4/img/wenhao.png" width="24" height="24"/>');
                                   } else {
                                       $scope.feeDetail = null;
                                       $scope.feemsg = $sce.trustAsHtml('未能为您预估费用.');
                                   }

                               }, function (error) {
                                   $scope.feeDetail = null;
                                   $scope.feemsg = $sce.trustAsHtml('未能为您预估费用.');
                               });

                           }

                           /**
                            * 初始化开始地址选择框
                            *
                            * @param locationInfo
                            */
                           function initBeginInput(locationInfo) {

                               $scope.task.beginAddress = locationInfo.name;
                               $scope.task.beginAddressDetail = locationInfo.address;
                               $scope.task.beginLat = locationInfo.point.lat;
                               $scope.task.beginLng = locationInfo.point.lng;

                               //开始地点
                               var stopBeginWatch = null;

                               $scope.beginSelect = function (poi) {

                                   if (!poi.address) {
                                       poi.address = poi.name;
                                   }

                                   $scope.task.beginAddress = poi.name;
                                   $scope.task.beginAddressDetail = poi.address;
                                   $scope.task.beginLat = poi.location.lat;
                                   $scope.task.beginLng = poi.location.lng;

                                   $scope.hideBeginTip = true;

                                   
                               }

                               $scope.stopWatchBeginInput = function () {

                                   if (stopBeginWatch) {
                                       stopBeginWatch();
                                   }
                               }

                               $scope.watchBeginInput = function () {
                                   $scope.hideBeginTip = false;
                                   //开始地点
                                   stopBeginWatch =
                                       $scope.$watch('task.beginAddress', function (nv, ov) {
                                           if (nv != ov) {
                                               locationService.placeSearch(nv, locationInfo.city)
                                                   .then(function (resp) {
                                                       if (resp.data.status == 0) {
                                                           $scope.beginPois =
                                                               filterPoi(resp.data.results);
                                                       }
                                                   });
                                           }
                                       });
                               }
                           }

                           function initEndInput(locationInfo) {

                               //结束地点
                               var stopEndWatch = null;

                               $scope.endSelect = function (poi) {
                                   if (!poi.address) {
                                       poi.address = poi.name;
                                   }
                                   $scope.task.endAddress = poi.name;
                                   $scope.task.endAddressDetail = poi.address;
                                   $scope.task.endLat = poi.location.lat;
                                   $scope.task.endLng = poi.location.lng;

                                   $scope.hideEndTip = true;

                                   if ($scope.task.beginLat && $scope.task.beginLng
                                       && $scope.task.type) {
                                       calculationFee($scope.task.type.areaId, $scope.task.beginLat,
                                                      $scope.task.beginLng, $scope.task.endLat,
                                                      $scope.task.endLng);
                                   }
                               }

                               $scope.stopWatchEndInput = function () {

                                   if (stopEndWatch) {
                                       stopEndWatch();
                                   }
                               }
                               $scope.watchEndInput = function () {
                                   $scope.hideEndTip = false;
                                   //开始地点
                                   stopEndWatch =
                                       $scope.$watch('task.endAddress', function (nv, ov) {
                                           if (nv != ov) {
                                               locationService.placeSearch(nv, locationInfo.city)
                                                   .then(function (resp) {
                                                       if (resp.data.status == 0) {

                                                           $scope.endPois =
                                                               filterPoi(resp.data.results);
                                                       }
                                                   });
                                           }
                                       });
                               }
                           }

                           /**
                            * 过滤不合法的poi
                            *
                            * @param results
                            * @returns {Array.<*>}
                            */
                           function filterPoi(results) {

                               var arr = [];
                               for (var i = 0; i < results.length; i++) {
                                   var poi = results[i];
                                   if (poi.location) {
                                       arr.push(poi);
                                   }
                               }

                               return arr.reverse();
                           }

                           /**
                            * 显示预算费用详情
                            */
                           $scope.showFeeDetail = function () {

                               if ($scope.feeDetail) {

                                   if ($scope.feeDetail.pay_detail) {
                                       $scope.feeDetail.detail =
                                           $sce.trustAsHtml(
                                               $scope.feeDetail.pay_detail.replace(/\n/g, "<br/>"));
                                   }
                                   //弹出支付提示
                                   ngDialog.open({
                                                     template: '/assets/v4/partials/feeInfo.html',
                                                     overlay: true,
                                                     showClose: true,
                                                     scope: $scope
                                                 });

                               }
                           }

                           /**
                            * 预约跑腿订单
                            * @param phone
                            * @param typeId
                            * @param content
                            * @param startAddress
                            * @param startLat
                            * @param startLng
                            * @param shouldPay
                            * @param travelTime
                            * @param mileage
                            * @param startPrice
                            * @param mileagePrice
                            * @param travelTimePrice
                            * @param deliverAddress
                            * @param deliverLat
                            * @param deliverLng
                            */
                           function makeAnAppointment(phone, typeId, content, startAddress,
                                                      startLat, startLng, shouldPay, travelTime,
                                                      mileage, startPrice, mileagePrice,
                                                      travelTimePrice, deliverAddress, deliverLat,
                                                      deliverLng) {

                               var promise = paotuiService.makeAnAppointment(cfg.sysKey, phone,
                                                                             typeId, content,
                                                                             startAddress, startLat,
                                                                             startLng, shouldPay,
                                                                             travelTime, mileage,
                                                                             startPrice,
                                                                             mileagePrice,
                                                                             travelTimePrice,
                                                                             deliverAddress,
                                                                             deliverLat, deliverLng,
                                                                             $rootScope.openId);

                               promise.then(function (result) {

                                   if (result.code == 0) {
                                	   $(".main_image").hide();

                                       $location.path('/success').search({
                                                                             'orderId': result.data.id,
                                                                             'type': 'paotui'
                                                                         });

                                   } else {
                                	   alert(result.message);
//                                       alert('下单失败');
                                   }

                               }, function (error) {

                                   alert('下单失败');

                               });
                           }

                           //入口
                           var promise = locationService.locateMe($rootScope);

                           promise.then(function (locationInfo) {

                               var promise = paotuiService.getServiceTypes(cfg.sysKey, cfg.ack,
                                                                           $scope.task.passengerId,
                                                                           locationInfo.point.lat,
                                                                           locationInfo.point.lng)

                               promise.then(function (types) {

                                   $scope.types = types;

                                   if (types.length > 0) {
                                       $scope.task.type = types[0];

                                       $scope.endAddressHit =
                                           $scope.task.type.endHint + ($scope.task.type.endAddress
                                               ? "" : "(选填)");

                                       //查询附近服务人员
                                       countNearEmploys(locationInfo.point.lat,
                                                        locationInfo.point.lng,
                                                        $scope.task.type.companyId);
                                   } else {
                                       $scope.tip = $sce.trustAsHtml('您的附近暂时没有服务人员');
                                   }
                                   //获取广告
                                   getAdvs(locationInfo);

                                   //初始化化开始选择框
                                   initBeginInput(locationInfo);
                                   
                                   if ($scope.task.beginLat && $scope.task.beginLng
                                       && $scope.task.type) {
                                       calculationFee($scope.task.type.areaId, $scope.task.beginLat,
                                                      $scope.task.beginLng, $scope.task.endLat,
                                                      $scope.task.endLng);
                                   }

                                   //初始化结束选择框
                                   initEndInput(locationInfo);

                               });

                               //立即预约
                               $scope.submit = function () {
                            	   
                            	   

                                   //验证表单
                                   var params = $scope.task;

                                   if (!params.content) {
                                       alert('请把您的需求告诉我');
                                       return;
                                   }
                                   
                                   if (!params.beginAddress || !params.beginLat
                                       || !params.beginLng) {
                                       alert('请先输入并选择预约地址');
                                       return;
                                   }

                                   if (!params.phone) {
                                       alert('请先输入手机号码');
                                       return;
                                   }

                                   if (!(/^0?1\d{10}$/.test(params.phone))) {
                                       alert('请先输入正确的手机号码');
                                       return;
                                   }

                                   if (!params.type) {
                                       alert('请选择跑腿类型');
                                       return;
                                   }
                                   
									if($scope.task.type.endAddress){
										if(!params.endLat || !params.endLng || !params.endAddress){
	                             		   alert('请输入任务目的地');
	                            		   return;
										}
									}


                                   //验证手机号是否已经绑定,未绑定发送验证码
                                   var promise = userService.checkBind(cfg.appId, cfg.sysKey,
                                                                       params.phone,
                                                                       $rootScope.openId);

                                   promise.then(function (result) {
                                       if (result.isBind) {
                                    	   $("#paotuiButton").attr("disabled",true);
                                           //执行下单逻辑
                                           var feeInfo = $scope.feeDetail;
                                           makeAnAppointment(params.phone, params.type.id,
                                                             params.content, params.beginAddress,
                                                             params.beginLat, params.beginLng,
                                                             feeInfo.money, feeInfo.travelTime,
                                                             feeInfo.mileage, feeInfo.startPrice,
                                                             feeInfo.mileagePrice,
                                                             feeInfo.travelTimePrice,
                                                             params.endAddress, params.endLat,
                                                             params.endLng);
                                       }
                                       else if (result.isSend) {
                                           //发送验证码,验证验证码
                                           //跳转登录界面
                                           var dialog = ngDialog.open({
                                                                          template: '/assets/v4/partials/validatecode.html',
                                                                          showClose: false,
                                                                          overlay: true,
                                                                          controller: function ($scope,
                                                                                                params) {

                                                                              $scope.phone =
                                                                                  params.phone;

                                                                              $scope.validate =
                                                                                  function () {
                                                                                      //验证信息
                                                                                      if (!$scope.vcode) {
                                                                                          alert(
                                                                                              '请先输入验证码信息');
                                                                                          return;
                                                                                      }

                                                                                      userService.checkCode(
                                                                                          cfg.appId,
                                                                                          cfg.sysKey,
                                                                                          $scope.phone,
                                                                                          $scope.vcode,
                                                                                          $rootScope.openId,
                                                                                          $rootScope.currentLocation.city)
                                                                                          .then(
                                                                                              function (resp) {
                                                                                                  if (resp.success) {
                                                                                                      //验证成功
                                                                                                      dialog.close(
                                                                                                          true);
                                                                                                  } else {
                                                                                                      alert(
                                                                                                          resp.message);
                                                                                                  }

                                                                                              },
                                                                                              function (error) {
                                                                                                  alert(
                                                                                                      '验证失败,请稍后再试');
                                                                                              });
                                                                                  }

                                                                          },
                                                                          resolve: {
                                                                              params: function () {
                                                                                  return $scope.task;
                                                                              }
                                                                          }
                                                                      });

                                           dialog.closePromise.then(function (data) {
                                               //执行下单逻辑
                                               if (data.value == true) {
                                                   var feeInfo = $scope.feeDetail;
                                                   makeAnAppointment(params.phone, params.type.id,
                                                                     params.content,
                                                                     params.beginAddress,
                                                                     params.beginLat,
                                                                     params.beginLng, feeInfo.money,
                                                                     feeInfo.travelTime,
                                                                     feeInfo.mileage,
                                                                     feeInfo.startPrice,
                                                                     feeInfo.mileagePrice,
                                                                     feeInfo.travelTimePrice,
                                                                     params.endAddress,
                                                                     params.endLat, params.endLng);
                                               }
                                           });

                                       } else {
                                           alert('验证码发送失败,请稍后再试');
                                       }
                                   });
                               }

                           }, function (error) {
                               if (error.code == 1) {
                                   alert('没有权限使用地理定位API');
                               } else if (error.code == 2) {
                                   alert('无法确定设备的位置');
                               } else if (error.code == 3) {
                                   alert('定位超时');
                               }
                           });

                       });
//专线控制器
controllers.controller('ZhuanxianCtrl',
                       function ($scope, $rootScope, $sce, $uibModal, $parse, $routeParams, $filter,
                                 $location, $window, gobalService, zhuanxianService,
                                 locationService,settingService, userService, ngDialog) {

							ngDialog.closeAll();
                           var lat = null;
                           var lng = null;
                           var lineAreaId = null;//收费ID
                           var typeTmep = null;//类型
                           var initLng = null;//初始经度
                           var initLat = null;//初始纬度
                           var initName = null;//初始地点名
                           var peopleNumber = null; //拼车人数
                           var carNumber = null; //包车辆数
                           var moneyAll = null; //预算金额
                           
                           Date.prototype.Format = function (fmt) {
                               var o = {
                                   "M+": this.getMonth() + 1,                 //月份
                                   "d+": this.getDate(),                    //日
                                   "h+": this.getHours(),                   //小时
                                   "m+": this.getMinutes(),                 //分
                                   "s+": this.getSeconds(),                 //秒
                                   "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                                   "S": this.getMilliseconds()             //毫秒
                               };
                               if (/(y+)/.test(fmt)) {
                                   fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                               }
                               for (var k in o)
                                   if (new RegExp("(" + k + ")").test(fmt))
                                       fmt =
                                               fmt.replace(RegExp.$1,
                                                           (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(
                                                                   ("" + o[k]).length)));
                               return fmt;
                           }
                           
                           var newdata = new Date().Format("yyyy/MM/dd hh:mm");
                           
                           
                           
                           
                           
                           
                           var cfg = gobalService.config();
                           var nav = angular.element('nav');

                           if (nav) {
                               nav.show();
                           }
                           angular.element('ul.nav_line > li > a').removeClass('nav_click');
                           angular.element('#zhuanxian').addClass('nav_click');

                           $scope.zhuanxian = {};
                           
                           if (isFromWx()) {
                               if ($rootScope.openId) {
                                   userService.findWxBind(cfg.sysKey, $rootScope.openId)
                                       .then(function (result) {
                                           if (result.code == 0) {
                                               var bindData = result.data;
                                               $scope.zhuanxian.phone = bindData.phone;
                                               $scope.zhuanxian.passengerId = bindData.passengerId;

                                               $rootScope.passengerId = bindData.passengerId;
                                               $rootScope.passengerPhone = bindData.phone;
                                               
                                               runningZhuanxian();
                                         
                                               
                                               zhuanxianService.findZXCouponV4(cfg.sysKey,
                                                       $scope.zhuanxian.passengerId)
            					               .then(function (coupons) {
            					                   if (coupons != null && coupons.length != 0) {
            					                	   var couponType = coupons[0].couponRule.money != null ? '优惠券抵扣'+ coupons[0].couponRule.money+ '元': '优惠券折扣' + coupons[0].couponRule.discount + '折';
            					                       $scope.coupon =
            					                           $sce.trustAsHtml('<span style="font-size:15px;">'+couponType+'<span>');
            					                       $scope.couponId = coupons[0].id;
            					                   }
            					               });
                                               
                                           }
                                       });
                               } else {
                                   $location.path('/index'); //跳转到首页
                               }

                           } 
                           function runningZhuanxian(){
                          	 
                               
                               zhuanxianService.findZhuanXianOrder(cfg.sysKey,
                                       $scope.zhuanxian.passengerId)
					           .then(function (result) {
					               if (result != null && result.length != 0) {
					//alert("您有未完成的专线订单");
					                   var dialog = ngDialog.open({
					                                                  template: '/assets/v4/partials/notorder.html',
					                                                  overlay: true,
					                                                  showClose: true,
					                                                  scope: $scope
					                                              });
					                   $scope.into = function () {
					
					                       var promise = zhuanxianService.findZXOrder(cfg.sysKey,
					                                                                  result[0].id);
					
					                       promise.then(function (fruit) {
					
					                           if (fruit.code == 0) {
					                               dialog.close(true);
					
					                               var orderInfo = fruit.data;
					                               var driverId = null;
					
					                               $scope.bookTime = orderInfo.serverTime;
					                               $scope.beginAddress = orderInfo.startAddress;
					                               $scope.endAddress = orderInfo.endAddress;
					                               $scope.phone = orderInfo.passengerPhone;
					
					                               if (orderInfo.status == 6) { //已经销单
					                                   //跳转到主页
					                                   $location.path('/index');
					                                   $location.replace();
					                               }
					                               else if (orderInfo.status == 0
					                                        || orderInfo.status == 1
					                                        || orderInfo.status == 2
					                                        || orderInfo.status == 3
					                                        || orderInfo.status == 4) { //司机已接单
					
					                                   //跳转到下单成功界面
					                                   /*$location.path('/success').search({
					                                                                         'orderId': orderInfo.id,
					                                                                         'type': 'zhuanxian'
					                                                                     });*/
					                            	   $location.path('/execute').search({
                                                           'orderId': orderInfo.id,
                                                           'type': 'zhuanxian'
                                                       });
					
					                                   /*//显示订单信息
					                                   $scope.title = "司机正赶往您的预约地";
					                                   $scope.acceptTime = orderInfo.acceptTime; //接单时间
					
					                                   if (orderInfo.status == 3) {
					                                       $scope.arriveTime = orderInfo.arriveTime;//到达预约地时间
					                                       $scope.title = "司机已到达预约地";
					                                       $scope.hideArrive = false;
					                                   }
					
					                                   if (orderInfo.status == 4) {
					                                       $scope.startdriveTime =
					                                           orderInfo.startdriveTime; //出发时间
					                                       $scope.title = "司机正前往目的地";
					                                       $scope.hideStartDrive = false;
					
					                                       if (orderInfo.treatment) { //跳转支付界面
					                                           $location.path('/payment').search({
					                                                                                 'orderId': orderInfo.id,
					                                                                                 'type': 'zhuanxian'
					                                                                             });
					                                           return;
					                                       }
					                                   }
					
					                                   //查询司机信息和位置信息
					                                   if (driverId != orderInfo.employId) {
					                                       driverId = orderInfo.employId;
					                                       findDriverInfo(driverId,
					                                                      orderInfo.startLat,
					                                                      orderInfo.startLng);
					                                   }
					
					                                   setTimeout(runningZhuanxian(), 5000);//请求成功间隔一秒再次请求
*/            						
					                               }
					                               else if (orderInfo.status == 5) { //已完成
					                                   //跳转完成界面
					                                   alert('订单已完成');
					                                   $location.path("/index");
					                               }
					
					                           }
					
					                       }, function (error) {
					                           setTimeout(runningZhuanxian(), 5000);//请求成功间隔一秒再次请求
					                       });
					
					                   }
					
					               }
					           });
                         }
                           
                           
                           
                               /*$scope.zhuanxian.passengerId = 21;
                               $scope.zhuanxian.phone = 13880445647;
                               runningZhuanxian();*/

                           

                           $scope.hideBeginTip = true;
                           $scope.hideEndTip = true;

                           $scope.hidePois = function () {
                               $scope.hideBeginTip = true;
                               $scope.hideEndTip = true;
                           }

                           $scope.showSelect = function () {
                               $scope.hideTypeList = false;
                           }
                           
                           $scope.change = function(startCity,endCity){
                        	   $scope.startCity = endCity;
                        	   $scope.endCity = startCity;
                        	   
                           }

                           /**
                            * 预约专线订单
                            */
                           function makeAnAppointment(orderType, passengerId, passengerPhone,
                                                      lineId, startAddress, startLat, startLng,
                                                      endAddress, endLat, endLng,
                                                      startTime, budgetPay, couponId, peopleNumber,
                                                      memo, takeDeliveryName, takeDeliveryPhone, lat, lng) {


                               var promise = zhuanxianService.makeAnZXAppointmentV4(cfg.sysKey,
                                                                                    orderType,
                                                                                    passengerId,
                                                                                    passengerPhone,
                                                                                    lineId,
                                                                                    startAddress,
                                                                                    startLat,
                                                                                    startLng,
                                                                                    endAddress,
                                                                                    endLat, endLng,
                                                                                    startTime,
                                                                                    budgetPay,
                                                                                    couponId,
                                                                                    peopleNumber,
                                                                                    memo,
                                                                                    takeDeliveryName,
                                                                                    takeDeliveryPhone,
                                                                                    cfg.ack, lat,
                                                                                    lng,
                                                                                    $rootScope.openId);

                               promise.then(function (result) {
                                   var orderId;

                                   if (result.code == 0) {
                                       if (null != result.data) {
                                           orderId = result.data[0].id;
                                       }
                                       $(".main_image").hide();

                                       $location.path('/success').search({
                                                                             'orderId': orderId,
                                                                             'type': 'zhuanxian'
                                                                         });

                                   } else {
                                       alert(result.message);
                                   }

                               }, function (error) {

                                   alert('下单失败');

                               });
                           }
                           
                           $scope.showFeeDetail = function () {

                               if ($scope.feeDetail) {

                                   if ($scope.feeDetail.pay_detail) {
                                       $scope.feeDetail.detail =
                                           $sce.trustAsHtml(
                                               $scope.feeDetail.pay_detail.replace(/\n/g, "<br/>"));
                                   }
                                   //弹出支付提示
                                   ngDialog.open({
                                                     template: '/assets/v4/partials/feeInfo.html',
                                                     overlay: true,
                                                     showClose: true,
                                                     scope: $scope
                                                 });

                               }
                           }
                           $scope.stopPeopleNumber = function () {
                        	   if ($scope.zhuanxian.beginLat && $scope.zhuanxian.beginLng
                                       && lineAreaId) {
                        		   peopleNumber = $scope.zhuanxian.peopleNumber;
	                        	   calculationFee(lineAreaId, $scope.zhuanxian.beginLat,
	                                       $scope.zhuanxian.beginLng, $scope.zhuanxian.endLat,
	                                       $scope.zhuanxian.endLng);
                        	   }
                           }
                           $scope.stopCarNumber = function () {
                        	   if ($scope.zhuanxian.beginLat && $scope.zhuanxian.beginLng
                                       && lineAreaId) {
                        		   carNumber = $scope.zhuanxian.carNumber;
                        		   
                        	   calculationFee(lineAreaId, $scope.zhuanxian.beginLat,
                                       $scope.zhuanxian.beginLng, $scope.zhuanxian.endLat,
                                       $scope.zhuanxian.endLng);
                        	   }
                           }
                           /**
                            * 预算费用
                            *
                            * @param areaId
                            * @param beginLat
                            * @param beginLng
                            * @param endLat
                            * @param endLng
                            */
                           function calculationFee(areaId, beginLat, beginLng, endLat, endLng) {
                               $scope.feemsg = $sce.trustAsHtml('正在为您预估费用...');
                               
                               var promise = zhuanxianService.calculation(cfg.sysKey, areaId, beginLat,
                                                                       beginLng, endLat, endLng);
                               promise.then(function (result) {

                                   if (result.code==0) {
                                       $scope.feeDetail = result.data;
                                       moneyAll = result.data.money;
                                       if(peopleNumber!=null && peopleNumber!=""){
                                    	   
                                    	   moneyAll = result.data.money * peopleNumber;
                                           
                                       }else if(carNumber!=null && carNumber!=""){
                                    	   
                                    	   moneyAll = result.data.money * carNumber;
                                           
                                       }else{
                                    	   moneyAll =  result.data.money;
                                           
                                       }
                                       
                                       $scope.feemsg =$sce.trustAsHtml('约<b style="font-size: 25px;">' + moneyAll.toFixed(1)
                                               + '</b>元<img src="/assets/v4/img/wenhao.png" width="24" height="24"/>');
                                   } else {
                                       $scope.feeDetail = null;
                                       $scope.feemsg = $sce.trustAsHtml('未能为您预估费用.');
                                   }

                               }, function (error) {
                                   $scope.feeDetail = null;
                                   $scope.feemsg = $sce.trustAsHtml('未能为您预估费用.');
                               });

                           }
                           
                           /**
                            * 初始化开始地址选择框
                            *
                            * @param locationInfo
                            */
                           function initBeginInput(locationInfo) {

                               /*$scope.zhuanxian.beginAddress = locationInfo.name;
                               $scope.zhuanxian.beginLat = locationInfo.point.lat;
                               $scope.zhuanxian.beginLng = locationInfo.point.lng;
                              initName = locationInfo.name;
                               initLat = locationInfo.point.lat;
                               initLng = locationInfo.point.lng;*/
                               

                               //开始地点
                               var stopBeginWatch = null;

                               $scope.beginSelect = function (poi) {

                                   if (!poi.address) {
                                       poi.address = poi.name;
                                   }

                                   $scope.zhuanxian.beginAddress = poi.name;
                                   $scope.zhuanxian.beginLat = poi.location.lat;
                                   $scope.zhuanxian.beginLng = poi.location.lng;

                                   $scope.hideBeginTip = true;
                                   
                                   if ($scope.zhuanxian.beginLat && $scope.zhuanxian.beginLng
                                           && lineAreaId) {
                                           calculationFee(lineAreaId, $scope.zhuanxian.beginLat,
                                                          $scope.zhuanxian.beginLng, $scope.zhuanxian.endLat,
                                                          $scope.zhuanxian.endLng);
                                       }

                               }

                               $scope.stopWatchBeginInput = function () {
                                   if (stopBeginWatch) {
                                       stopBeginWatch();
                                   }
                               }

                               $scope.watchBeginInput = function () {
                                   $scope.hideBeginTip = false;
                                   //开始地点
                                   stopBeginWatch =
                                       $scope.$watch('zhuanxian.beginAddress', function (nv, ov) {
                                           if (nv != ov) {
                                               locationService.placeCitySearch(nv,
                                                                           $scope.startCity.split(
                                                                               "-")[1])
                                                   .then(function (resp) {
                                                       if (resp.data.status == 0) {
                                                           $scope.beginPois =
                                                               filterPoi(resp.data.results);
                                                       }
                                                   });
                                           }
                                       });
                               }
                           }
                           

                           function initEndInput(locationInfo) {

                               //结束地点
                               var stopEndWatch = null;

                               $scope.endSelect = function (poi) {
                                   if (!poi.address) {
                                       poi.address = poi.name;
                                   }
                                   $scope.zhuanxian.endAddress = poi.name;
                                   $scope.zhuanxian.endLat = poi.location.lat;
                                   $scope.zhuanxian.endLng = poi.location.lng;

                                   $scope.hideEndTip = true;
                                   
                                   if ($scope.zhuanxian.beginLat && $scope.zhuanxian.beginLng
                                           && lineAreaId) {
                                           calculationFee(lineAreaId, $scope.zhuanxian.beginLat,
                                                          $scope.zhuanxian.beginLng, $scope.zhuanxian.endLat,
                                                          $scope.zhuanxian.endLng);
                                       }

                               }

                               $scope.stopWatchEndInput = function () {

                                   if (stopEndWatch) {
                                       stopEndWatch();
                                   }
                               }
                               $scope.watchEndInput = function () {
                                   $scope.hideEndTip = false;
                                   //开始地点
                                   stopEndWatch =
                                       $scope.$watch('zhuanxian.endAddress', function (nv, ov) {
                                           if (nv != ov) {
                                               locationService.placeCitySearch(nv, $scope.endCity.split(
                                                   "-")[1]).then(function (resp) {
                                                   if (resp.data.status == 0) {
                                                       $scope.endPois =
                                                           filterPoi(resp.data.results);
                                                   }
                                               });
                                           }
                                       });
                               }
                           }
                           
                           /**
                            * 查询广告信息
                            */
                           function getAdvs(locationInfo) {
                               var promise = settingService.getAdvs(cfg.sysKey, cfg.ack,
                                                                    locationInfo.point.lat,
                                                                    locationInfo.point.lng,
                                                                    $rootScope.passengerId);
                               promise.then(function (result) {
                                   if (result.code == 0) {
                                       var imgs = result.data;
                                       if (imgs) {
                                           var li = '<div class="main_image"><ul >';

                                           for (var i = 0; i < imgs.length; i++) {
                                               li +=
                                                   '<li><a href="' + imgs[i].linkAddress
                                                   + '"><img src="http://' + result.address + '/'
                                                   + imgs[i].picture + '"/></a></li>'
                                           }

                                           li +=
                                               '</ul> <a href="javascript:;" id="btn_prev"></a><a href="javascript:;" id="btn_next"></a></div>';

                                           jQuery("#adv").html(li);
                                           //调用滚动
                                           silder();
                                       }
                                   }
                               });
                           }

                           /**
                            * 过滤不合法的poi
                            *
                            * @param results
                            * @returns {Array.<*>}
                            */
                           function filterPoi(results) {

                               var arr = [];
                               for (var i = 0; i < results.length; i++) {
                                   var poi = results[i];
                                   if (poi.location) {
                                       arr.push(poi);
                                   }
                               }

                               return arr.reverse();
                           }

                           locationService.locateMe($rootScope).then(function (locationInfo) {

                               lat = locationInfo.point.lat;
                               lng = locationInfo.point.lng;
                               
                               //获取广告信息
                               getAdvs(locationInfo);

                               //初始化化开始选择框
                               initBeginInput(locationInfo);
                               
                               

                               //初始化结束选择框
                               initEndInput(locationInfo);

                               zhuanxianService.findLineAll(cfg.sysKey, locationInfo.point.lat,
                                                            locationInfo.point.lng)
                                   .then(function (result) {
                                       $scope.cityTypes = result;

                                       var array = [];
                                       angular.forEach($scope.cityTypes, function (data, index) {
                                           zhuanxianService.findBylineId(cfg.sysKey, data.id)
                                               .then(function (money) {
                                                   array.push($.extend({}, money.data, data));
                                                   $scope.moneys = array;
                                               });

                                       });

                                   });
                               $scope.startSelect = function () {

                                   var keys = [];

                                   angular.forEach($scope.cityTypes, function (item, index) {
                                       var key = item.startCity;
                                       if (keys.indexOf(key) == -1) {
                                           keys.push(key);
                                       }
                                   });
                                   $scope.startCitys = keys;

                                   

                                   var startlog = ngDialog.open({
                                                                    template: '/assets/v4/partials/startcity.html',
                                                                    overlay: true,
                                                                    showClose: true,
                                                                    scope: $scope
                                                                });
                                   $scope.startClick = function (cityType, $event) {
                                       $scope.zhuanxian.beginAddress = "";
                                       $scope.zhuanxian.beginLat = "";
                                       $scope.zhuanxian.beginLng = "";
                                       $scope.startCity = cityType;
                                       
                                       $scope.startCity = cityType;
                                       
                                       zhuanxianService.findLineAllByStart(cfg.sysKey, cityType).then(function (result) {
                                    	   $scope.endCity = result[0].endCity;
                                    	   
                                    	   zhuanxianService.findLineAllBySE(cfg.sysKey,$scope.startCity,$scope.endCity).then(function (data) {
                                    		   if (data.length > 0) {
					                               	   $scope.feemsg=$sce.trustAsHtml("");
					                               	   
					                               	   
					                               	   if (typeTmep!=null && typeTmep==0) {
					                               		   lineAreaId = data[0].areaId;
					                                      } else if (typeTmep!=null && typeTmep==1) {
					                                   	   lineAreaId = data[0].baocheAreaId;
					                                      } else if (typeTmep!=null && typeTmep==2) {
					                                   	   lineAreaId = data[0].jihuoAreaId;
					                                      }else if ($routeParams.class == 'pincheClass') {
					                                   	   lineAreaId = data[0].areaId;
					                                      } else if ($routeParams.class == 'baocheClass') {
					                                   	   lineAreaId = data[0].baocheAreaId;
					                                      } else if ($routeParams.class == 'jihuoClass') {
					                                   	   lineAreaId = data[0].jihuoAreaId;
					                                      }
					                               	   
					                               	   
					                               	   if ($scope.zhuanxian.beginLat && $scope.zhuanxian.beginLng
					                                              && lineAreaId) {
					                                              calculationFee(lineAreaId, $scope.zhuanxian.beginLat,
					                                                             $scope.zhuanxian.beginLng, $scope.zhuanxian.endLat,
					                                                             $scope.zhuanxian.endLng);
					                                          }
					
					
					                              $scope.lineId = data[0].id;
					                          } else {
					                              alert("未找到路线，请重新选择！");
					                          }
					                      });
                                    	   
                                    	   
                                    	   
                                       });
                                       
                                       startlog.close(true);

                                   }

                               }
                               $scope.endSelect1 = function () {

                                   zhuanxianService.findLineAllByStart(cfg.sysKey, $scope.startCity)
                                       .then(function (result) {

                                           $scope.endCitys = result;

                                           var keys = [];

                                           angular.forEach($scope.endCitys, function (item, index) {
                                               var key = item.endCity;
                                               if (keys.indexOf(key) == -1) {
                                                   keys.push(key);
                                               }
                                           });
                                           $scope.seclectEndCitys = keys;

                                           var endlog = ngDialog.open({
                                                                          template: '/assets/v4/partials/endcity.html',
                                                                          overlay: true,
                                                                          showClose: true,
                                                                          scope: $scope
                                                                      });

                                           $scope.endClick = function (endCity, $event) {
                                               $scope.zhuanxian.endAddress = "";
                                               $scope.zhuanxian.endLat = "";
                                               $scope.zhuanxian.endLng = "";
                                               $scope.endCity = endCity;
                                               endlog.close(true);

                                               zhuanxianService.findLineAllBySE(cfg.sysKey,
                                                                                $scope.startCity,
                                                                                $scope.endCity)
                                                   .then(function (data) {
                                                       if (data.length > 0) {
                                                            	   $scope.feemsg=$sce.trustAsHtml("");
                                                            	   
                                                            	   
                                                            	   if (typeTmep!=null && typeTmep==0) {
                                                            		   lineAreaId = data[0].areaId;
                                                                   } else if (typeTmep!=null && typeTmep==1) {
                                                                	   lineAreaId = data[0].baocheAreaId;
                                                                   } else if (typeTmep!=null && typeTmep==2) {
                                                                	   lineAreaId = data[0].jihuoAreaId;
                                                                   }else if ($routeParams.class == 'pincheClass') {
                                                                	   lineAreaId = data[0].areaId;
                                                                   } else if ($routeParams.class == 'baocheClass') {
                                                                	   lineAreaId = data[0].baocheAreaId;
                                                                   } else if ($routeParams.class == 'jihuoClass') {
                                                                	   lineAreaId = data[0].jihuoAreaId;
                                                                   }
                                                            	   
                                                            	   
                                                            	   if ($scope.zhuanxian.beginLat && $scope.zhuanxian.beginLng
                                                                           && lineAreaId) {
                                                                           calculationFee(lineAreaId, $scope.zhuanxian.beginLat,
                                                                                          $scope.zhuanxian.beginLng, $scope.zhuanxian.endLat,
                                                                                          $scope.zhuanxian.endLng);
                                                                       }


                                                           $scope.lineId = data[0].id;
                                                       } else {
                                                           alert("未找到路线，请重新选择！");
                                                       }
                                                   })
                                           }

                                       });
                               }


                               $scope.back = function () {
                                   $window.history.back();
                               }

                               $scope.order = function (money, $event) {
                            	   

                                   var carAreaId;
                                   if ($event.currentTarget.attributes[0].nodeValue
                                       == 'pincheClass') {
                                	   carAreaId = money.areaId;
                                   } else if ($event.currentTarget.attributes[0].nodeValue
                                              == 'baocheClass') {
                                	   carAreaId = money.baocheAreaId;
                                   } else if ($event.currentTarget.attributes[0].nodeValue
                                              == 'jihuoClass') {
                                	   carAreaId = money.jihuoAreaId;
                                   }
                                   $location.path('/order').search({
                                                                       'class': $event.currentTarget.attributes[0].nodeValue,
                                                                       'startCity': money.startCity,
                                                                       'endCity': money.endCity,
                                                                       'lineId': money.id,
                                                                       'money': money,
                                                                       'carAreaId': carAreaId
                                                                   });
                                   /*$scope.zhuanxian.peopleNumber = 1;
                        		   $scope.zhuanxian.carNumber = 1;*/
                                   if ($scope.zhuanxian.beginLat && $scope.zhuanxian.beginLng
                                           && carAreaId) {
                                           calculationFee(carAreaId, $scope.zhuanxian.beginLat,
                                                          $scope.zhuanxian.beginLng, $scope.zhuanxian.endLat,
                                                          $scope.zhuanxian.endLng);
                                       }

                               }
                               
                               
                               $scope.carMoneyClick = function(target){
                            	   $scope.startCity = $routeParams.startCity;
                            	   $scope.endCity = $routeParams.endCity;
                            	   $scope.lineId = $routeParams.lineId;
                            	   $scope.feemsg = "";
                            	   peopleNumber = null;
                        		   carNumber = null;
                        		  /* $scope.zhuanxian.peopleNumber = 1;
                        		   $scope.zhuanxian.carNumber = 1;*/
                            	   $scope.zhuanxian.beginAddress = initName;
                                   $scope.zhuanxian.beginLat = initLat;
                                   $scope.zhuanxian.beginLng = initLng;
                        		   $scope.zhuanxian.endAddress = null;
                        		   $scope.zhuanxian.endLat = null;
                                   $scope.zhuanxian.endLng = null;
                            	   if (target==0) {
                            		   
                            		   lineAreaId = $routeParams.money.areaId;
                            		   typeTmep = 0;
                                   } else if (target==1) {
                                	   typeTmep = 1;
                                	   lineAreaId = $routeParams.money.baocheAreaId;
                                   } else if (target==2) {
                                	   typeTmep = 2;
                                	   lineAreaId = $routeParams.money.jihuoAreaId;
                                   }
                            	   if ($scope.zhuanxian.beginLat && $scope.zhuanxian.beginLng
                                           && lineAreaId) {
	                            		   
	                            		   
                                           calculationFee(lineAreaId, $scope.zhuanxian.beginLat,
                                                          $scope.zhuanxian.beginLng, $scope.zhuanxian.endLat,
                                                          $scope.zhuanxian.endLng);
                                       }
                               }
                               
                               lineAreaId = $routeParams.carAreaId;
                               $scope.startCity = $routeParams.startCity;
                               $scope.endCity = $routeParams.endCity;
                               $scope.lineId = $routeParams.lineId;
                               $("#test").val(newdata);
                               //立即预约
                               $scope.submit = function () {
                                   var peopleNumber = null;
                                   
                                   

                                   //验证表单

                                   /*$.ajax({
                                              url: "/h5/v4/zhuanxian/findLineAllBySE",
                                              type: 'GET',
                                              async: false,
                                              dataType: 'json',
                                              data: {
                                                  "appkey": cfg.sysKey,
                                                  "startCity": $scope.startCity,
                                                  "endCity": $scope.endCity
                                              },
                                              success: function (data) {
                                                  if (data.length < 0 || data == "") {
                                                      alert("路线错误，请重新选择路线");
                                                      return false;
                                                  }
                                              }
                                          });*/

                                   var params = $scope.zhuanxian;

                                   if ($("#orderType").val() == 0) {
                                       peopleNumber = params.peopleNumber;
                                   } else if ($("#orderType").val() == 1) {
                                       peopleNumber = params.carNumber;
                                   }

                                   if ("" == $("#test").val()) {
                                       alert('请选择预约时间');
                                       return;
                                   }

                                   if (!params.beginAddress || !params.beginLat
                                       || !params.beginLng) {
                                       alert('请先输入并选择预约地址');
                                       return;
                                   }

                                   if (!params.phone) {
                                       alert('请先输入手机号码');
                                       return;
                                   }

                                   if (!(/^0?1\d{10}$/.test(params.phone))) {
                                       alert('请先输入正确的手机号码');
                                       return;
                                   }
                                   
                                   
                                   if($("#orderType").val()==0){
                                	   if (!params.peopleNumber) {
                                           alert('请先输入人数');
                                           return;
                                       }
                                	   if (!(/^[1-9]\d*$/.test(params.peopleNumber)) || params.peopleNumber > 7) {
                                    	   alert('请输入正确的人数(最多七个人)');
                                    	   return;
                                       }
                                   }
                                   if($("#orderType").val()==1){
                                	   if (!params.carNumber) {
                                           alert('请先输入车辆数量');
                                           return;
                                       }
                                	   if (!(/^[1-9]\d*$/.test(params.carNumber)) || params.carNumber > 7) {
                                    	   alert('请输入正确车辆数量(最多七辆)');
                                    	   return;
                                       }
                                   }
                                   if($("#orderType").val()==2){
                                	   
                                	   if (!params.takeDeliveryName) {
                                		   alert('请先输入收货人姓名');
                                		   return;
                                	   }
                                	   if (!params.takeDeliveryPhone) {
                                           alert('请先输入收货人电话');
                                           return;
                                       }
                                	   
                                	   if (!(/^0?1\d{10}$/.test(params.takeDeliveryPhone))) {
                                           alert('请先输入正确的收货人电话');
                                           return;
                                       } 
                                   }
                                   
                                   

                                   //验证手机号是否已经绑定,未绑定发送验证码
                                   var promise = userService.checkBind(cfg.appId, cfg.sysKey,
                                                                       params.phone,
                                                                       $rootScope.openId);

                                   promise.then(function (result) {
                                       if (result.isBind) {
                                    	   $("#zhuanxianButton").attr("disabled",true);
                                           //执行下单逻辑
                                           var feeInfo = $scope.feeDetail;
                                           makeAnAppointment($("#orderType").val(),
                                                             params.passengerId, params.phone,
                                                             $scope.lineId, params.beginAddress,
                                                             params.beginLat, params.beginLng,
                                                             params.endAddress, params.endLat,
                                                             params.endLng,
                                                             $("#test").val(), moneyAll,
                                                             $scope.couponId, peopleNumber,
                                                             params.memo, params.takeDeliveryName,
                                                             params.takeDeliveryPhone,initLat,initLng);
                                       }
                                       else if (result.isSend) {
                                           //发送验证码,验证验证码
                                           //跳转登录界面
                                           var dialog = ngDialog.open({
                                                                          template: '/assets/v4/partials/validatecode.html',
                                                                          showClose: false,
                                                                          overlay: true,
                                                                          controller: function ($scope,
                                                                                                params) {

                                                                              $scope.phone =
                                                                                  params.phone;

                                                                              $scope.validate =
                                                                                  function () {
                                                                                      //验证信息
                                                                                      if (!$scope.vcode) {
                                                                                          alert(
                                                                                              '请先输入验证码信息');
                                                                                          return;
                                                                                      }

                                                                                      userService.checkCode(
                                                                                          cfg.appId,
                                                                                          cfg.sysKey,
                                                                                          $scope.phone,
                                                                                          $scope.vcode,
                                                                                          $rootScope.openId,
                                                                                          $rootScope.currentLocation.city)
                                                                                          .then(
                                                                                              function (resp) {
                                                                                                  if (resp.success) {
                                                                                                      //验证成功
                                                                                                      dialog.close(
                                                                                                          true);
                                                                                                  } else {
                                                                                                      alert(
                                                                                                          resp.message);
                                                                                                  }

                                                                                              },
                                                                                              function (error) {
                                                                                                  alert(
                                                                                                      '验证失败,请稍后再试');
                                                                                              });
                                                                                  }

                                                                          },
                                                                          resolve: {
                                                                              params: function () {
                                                                                  return $scope.zhuanxian;
                                                                              }
                                                                          }
                                                                      });

                                           dialog.closePromise.then(function (data) {
                                               //执行下单逻辑
                                               if (data.value == true) {
                                                   var feeInfo = $scope.feeDetail;
                                                   makeAnAppointment($("#orderType").val(),
                                                                     params.passengerId,
                                                                     params.phone, $scope.lineId,
                                                                     params.beginAddress,
                                                                     params.beginLat,
                                                                     params.beginLng,
                                                                     params.endAddress,
                                                                     params.endLat, params.endLng,
                                                                     $("#test").val(),
                                                                     moneyAll,
                                                                     $scope.couponId, peopleNumber,
                                                                     params.memo,
                                                                     params.takeDeliveryName,
                                                                     params.takeDeliveryPhone,initLat,initLng);
                                               }
                                           });

                                       } else {
                                           alert('验证码发送失败,请稍后再试');
                                       }
                                   });
                               }

                           }, function (error) {
                               if (error.code == 1) {
                                   alert('没有权限使用地理定位API');
                               } else if (error.code == 2) {
                                   alert('无法确定设备的位置');
                               } else if (error.code == 3) {
                                   alert('定位超时');
                               }
                           });

                       });

//下单成功
controllers.controller('SuccessCtrl',
                       function ($scope, $rootScope, $routeParams, $location, $filter,
                                 daijiaService, zhuancheService, zhuanxianService, paotuiService,
                                 ngDialog,gobalService) {
							ngDialog.closeAll();
                           var cfg = gobalService.config();

                           var nav = angular.element('nav');

                           if (nav) {
                               nav.hide();
                           }

                           /**
                            * 查询代驾订单
                            */
                           function findDJOrder() {

                               var promise = daijiaService.findOrder(cfg.sysKey,
                                                                     $routeParams.orderId);

                               promise.then(function (result) {
                                   if (result.success) {
                                       var orderInfo = result.data;

                                       $scope.bookTime = orderInfo.serverTime;
                                       $scope.beginAddress = orderInfo.fromPlace;
                                       $scope.endAddress = orderInfo.toPlace;
                                       $scope.phone = orderInfo.clientPhone;

                                       if (orderInfo.status == 5) { //已经销单
                                           //跳转到主页
                                           $location.path('/index');
                                           $location.replace();
                                       }
                                       else if (orderInfo.status == 0 || orderInfo.status == 1) {

                                           setTimeout(findDJOrder, 1000);//请求成功间隔一秒再次请求

                                       }
                                       else if (orderInfo.status == 2) { //司机已接单

                                           if (orderInfo.treatment) { //司机已经确认支付信息
                                               //跳转到支付界面
                                               $location.path('/payment').search({
                                                                                     'orderId': $routeParams.orderId,
                                                                                     'type': $routeParams.type
                                                                                 });
                                               return;
                                           }

                                           //跳转接单界面
                                           $location.path('/execute', {
                                               'orderId': $routeParams.orderId,
                                               'type': $routeParams.type
                                           });

                                       }
                                       else if (orderInfo.status == 3 || orderInfo.status == 6) { //已完成
                                           //跳转完成界面
                                           alert('订单已完成');
                                           $location.path("/index");
                                       }

                                   }

                               }, function (error) {

                                   setTimeout(findDJOrder, 1000);//请求成功间隔一秒再次请求

                               });

                           }

                           /**
                            * 查询专车订单
                            */
                           function findZCOrder() {
                               var promise = zhuancheService.findOrder(cfg.sysKey,
                                                                       $routeParams.orderId);

                               promise.then(function (result) {

                                   if (result.success) {

                                       var orderInfo = result.data;

                                       $scope.bookTime = orderInfo.serverTime;
                                       $scope.beginAddress = orderInfo.startAddress;
                                       $scope.endAddress = orderInfo.endAddress;
                                       $scope.phone = orderInfo.passengerPhone;

                                       if (orderInfo.status == 6) { //已经销单
                                           //跳转到主页
                                           $location.path('/index');
                                           $location.replace();
                                       }
                                       else if (orderInfo.status == 0 || orderInfo.status == 1) {

                                           setTimeout(findZCOrder, 1000);//请求成功间隔一秒再次请求

                                       }
                                       else if (orderInfo.status == 2 || orderInfo.status == 3
                                                || orderInfo.status == 4) { //司机已接单

                                           if (orderInfo.status == 4 && orderInfo.treatment) { //司机已经确认支付信息
                                               //跳转到支付界面
                                               $location.path('/payment').search({
                                                                                     'orderId': $routeParams.orderId,
                                                                                     'type': $routeParams.type
                                                                                 });
                                               return;
                                           }

                                           //跳转接单界面
                                           $location.path('/execute', {
                                               'orderId': $routeParams.orderId,
                                               'type': $routeParams.type
                                           });

                                       }
                                       else if (orderInfo.status == 5) { //已完成
                                           //跳转完成界面
                                           alert('订单已完成');
                                           $location.path("/index");
                                       }

                                   }

                               }, function (error) {
                                   setTimeout(findZCOrder, 1000);//请求成功间隔一秒再次请求
                               });

                           }

                           function findZXOneOrder() {

                               var promise = zhuanxianService.findZXOrder(cfg.sysKey,
                                                                          $routeParams.orderId);

                               promise.then(function (result) {

                                   if (result.code == 0) {

                                       var orderInfo = result.data;

                                       $scope.bookTime = orderInfo.serverTime;
                                       $scope.beginAddress = orderInfo.startAddress;
                                       $scope.endAddress = orderInfo.endAddress;
                                       $scope.phone = orderInfo.passengerPhone;

                                       if (orderInfo.status == 6) { //已经销单
                                           //跳转到主页
                                           $location.path('/index');
                                           $location.replace();
                                       }
                                       else if (orderInfo.status == 0 || orderInfo.status == 1) {

                                           setTimeout(findZXOneOrder, 1000);//请求成功间隔一秒再次请求

                                       }
                                       else if (orderInfo.status == 2 || orderInfo.status == 3
                                                || orderInfo.status == 4) { //司机已接单

                                           if (orderInfo.status == 4 && orderInfo.treatment) { //司机已经确认支付信息
                                               //跳转到支付界面
                                               $location.path('/payment').search({
                                                                                     'orderId': $routeParams.orderId,
                                                                                     'type': $routeParams.type
                                                                                 });
                                               return;
                                           }

                                           //跳转接单界面
                                           $location.path('/execute', {
                                               'orderId': $routeParams.orderId,
                                               'type': $routeParams.type
                                           });

                                       }
                                       else if (orderInfo.status == 5) { //已完成
                                           //跳转完成界面
                                           alert('订单已完成');
                                           $location.path("/index");
                                       }

                                   }

                               }, function (error) {
                                   setTimeout(findZXOneOrder, 1000);//请求成功间隔一秒再次请求
                               });

                           }

                           /**
                            * 查询跑腿订单
                            */
                           function findPTOrder() {
                               var promise = paotuiService.findOrder(cfg.sysKey,
                                                                     $routeParams.orderId);

                               promise.then(function (result) {
                                   if (result) {
                                       var orderInfo = result;

                                       $scope.bookTime = orderInfo.startTime;
                                       $scope.beginAddress = orderInfo.startAddress;
                                       $scope.endAddress = orderInfo.deliverAddress;
                                       $scope.phone = orderInfo.passengerPhone;

                                       if (orderInfo.status == 5) { //已经销单
                                           //跳转到主页
                                            if (orderInfo.status == 5) {
                                               alert("您已被销单");
                                           }

                                           $location.path('/index');
                                           $location.replace();
                                       } else if (orderInfo.status == 0 || orderInfo.status == 1 || orderInfo.status == 2 || orderInfo.status == 3) { //司机已接单

                                           if (orderInfo.status == 3 && orderInfo.treatment) { //司机已经确认支付信息
                                               //跳转到支付界面
                                               $location.path('/payment').search({
                                                                                     'orderId': orderInfo.id,
                                                                                     'type': $routeParams.type
                                                                                 });
                                               return;
                                           }

                                           //跳转接单界面
                                           if (orderInfo.status == 2 || orderInfo.status == 3) {
                                        	   $location.path('/execute').search({
                                                   'orderId': orderInfo.id,
                                                   'type': $routeParams.type
                                               });
                                           }

                                           //跳转到下单成功界面
                                           /*$location.path('/success').search({
                                                                                 'orderId': orderInfo.id,
                                                                                 'type': $routeParams.type
                                                                             });*/
                                           setTimeout(findPTOrder, 1000);//请求成功间隔一秒再次请求

                                       }
                                       else if (orderInfo.status == 4) { //已完成
                                           //跳转完成界面
                                           alert('订单已完成');
                                           $location.path("/index");
                                       }

                                   }

                               }, function (error) {
                                   setTimeout(findPTOrder, 1000);//请求成功间隔一秒再次请求
                               });

                           }

                           if ($routeParams.type == 'daijia') {

                               findDJOrder();

                           } else if ($routeParams.type == 'zhuanche') {

                               findZCOrder();

                           } else if ($routeParams.type == 'paotui') {
                               findPTOrder(); //查询跑腿订单
                           } else if ($routeParams.type == 'zhuanxian') {
                               findZXOneOrder(); //查询专线订单
                           }

                           $scope.cancel = function () {

                               if ($routeParams.type == 'daijia') {
                                   //取消代驾
                                   $location.path('/cancel').search({
                                                                        'orderId': $routeParams.orderId,
                                                                        'type': $routeParams.type
                                                                    });
                               }
                               else if ($routeParams.type == 'zhuanche') {
                                   //取消专车
                                   $location.path('/cancel').search({
                                                                        'orderId': $routeParams.orderId,
                                                                        'type': $routeParams.type
                                                                    });
                               } else if ($routeParams.type == 'paotui') {
                                   //取消跑腿
                                   $location.path('/cancel').search({
                                                                        'orderId': $routeParams.orderId,
                                                                        'type': $routeParams.type
                                                                    });
                               } else if ($routeParams.type == 'zhuanxian') {
                                   //取消专线
                                   $location.path('/cancel').search({
                                                                        'orderId': $routeParams.orderId,
                                                                        'type': $routeParams.type
                                                                    });
                               }
                           }

                       });

//取消订单
controllers.controller('CancelCtrl', function ($scope, $rootScope, $routeParams, $window, $location,
                                               daijiaService, zhuancheService, zhuanxianService,
                                               ngDialog,paotuiService, gobalService) {

	
	ngDialog.closeAll();
    var nav = angular.element('nav');

    if (nav) {
        nav.hide();
    }

    if ($routeParams.type == 'daijia') {

        $scope.resons = [
            '我选择了其它交通方式',
            '司机让我等候太久',
            '司机无法来接我',
            '所在城市未开通服务'
        ]

    } else if ($routeParams.type == 'zhuanche') {

        $scope.resons = [
            '我改变了行程，不需要用车了',
            '我选择了其它交通方式',
            '司机让我等候太久',
            '司机无法来接我',
            '所在城市未开通服务'
        ]

    } else if ($routeParams.type == 'paotui') {
        $scope.resons = [
            '我改变了需求不需要了',
            '我选择了其它方式',
            '服务人员让我等候太久',
            '服务人员无法来为我服务',
            '所在城市未开通服务'
        ]
    } else if ($routeParams.type == 'zhuanxian') {
        $scope.resons = [
            '我改变了需求不需要了',
            '我选择了其它方式',
            '服务人员让我等候太久',
            '服务人员无法来为我服务',
            '所在城市未开通服务'
        ]
    }

    $scope.hideCustom = true;

    $scope.checkMe = function (reson) {

        if (reson == '自定义') {
            $scope.hideCustom = false;
            $scope.reson = null;
        } else {
            $scope.hideCustom = true;
            $scope.reson = reson;
        }

    }

    var cfg = gobalService.config();

    //确定取消
    $scope.submit = function () {

        if ($scope.reson == null || $scope.reson == '') {
            alert('请选择或者输入取消原因');
            return;
        }

        if ($routeParams.type == 'daijia') {

            var promise = daijiaService.cancelOrder(cfg.sysKey, $routeParams.orderId, $scope.reson);

            promise.then(function (result) {
                if (result.code == 0) {
                    alert('销单成功');
                    //跳转主页面
                    $location.path('/index');
                } else {
                    alert(result.msg);
                }
            });
        }
        else if ($routeParams.type == 'zhuanche') {

            var promise = zhuancheService.cancelOrder(cfg.sysKey, $routeParams.orderId,
                                                      $scope.reson);
            promise.then(function (result) {

                if (result.code == 0) {
                    alert('销单成功');
                    //跳转主页面
                    $location.path('/index');
                } else {
                    alert(result.message);
                }
            });

        } else if ($routeParams.type == 'paotui') {

            var promise = paotuiService.cancelOrder(cfg.sysKey, $routeParams.orderId, $scope.reson);
            promise.then(function (result) {

                if (result.success) {
                    alert('销单成功');
                    //跳转主页面
                    $location.path('/index');
                } else {
                    alert(result.message);
                }
            });

        } else if ($routeParams.type == 'zhuanxian') {

            var promise = zhuanxianService.cancelOrder(cfg.sysKey, $routeParams.orderId,
                                                       $scope.reson);
            promise.then(function (result) {

                if (result.success) {
                    alert('销单成功');
                    //跳转主页面
                    $location.path('/index');
                } else {
                    alert(result.message);
                }
            });

        }

    }

    //继续行程
    $scope.cancel = function () {
        $window.history.back();
    }

});

//订单执行中
controllers.controller('ExecuteCtrl',
                       function ($scope, $rootScope, $routeParams, $window, $location,
                                 daijiaService, zhuancheService, zhuanxianService, gobalService,paotuiService,
                                 ngDialog,driverService, locationService) {

							ngDialog.closeAll();
                           var cfg = gobalService.config();

                           var nav = angular.element('nav');

                           if (nav) {
                               nav.hide();
                           }

                           $scope.hideStartDrive = true;
                           $scope.hideArrive = true;

                           var driverId = null;

                           /**
                            * 查询代驾订单
                            */
                           function findDJOrder() {

                               var promise = daijiaService.findOrder(cfg.sysKey,
                                                                     $routeParams.orderId);

                               promise.then(function (result) {
                                   if (result.success) {

                                       var orderInfo = result.data;

                                       if (orderInfo.status == 5) { //已经销单
                                           //跳转到主页
                                           $location.path('/index');
                                           $location.replace();
                                       }
                                       else if (orderInfo.status == 0 || orderInfo.status == 1) {

                                           //跳转下单成功界面
                                           $location.path('/success', {
                                               'orderId': $routeParams.orderId,
                                               'type': $routeParams.type
                                           });

                                       }
                                       else if (orderInfo.status == 2) { //司机已接单

                                           if (orderInfo.treatment) { //司机已经确认支付信息
                                               //跳转到支付界面
                                               $location.path('/payment').search({
                                                                                     'orderId': $routeParams.orderId,
                                                                                     'type': $routeParams.type
                                                                                 });
                                               return;
                                           }

                                           //显示订单信息
                                           $scope.title = "司机正赶往您的预约地";
                                           $scope.acceptTime = orderInfo.acceptTime; //接单时间

                                           $scope.arriveTime = orderInfo.arriveTime;//到达预约地时间
                                           if (orderInfo.arriveTime) {
                                               $scope.title = "司机已到达预约地";
                                               $scope.hideArrive = false;
                                           }

                                           $scope.startdriveTime = orderInfo.startdriveTime; //出发时间
                                           if (orderInfo.startdriveTime) {
                                               $scope.title = "司机正前往目的地";
                                               $scope.hideStartDrive = false;
                                           }

                                           //查询司机信息和位置信息
                                           if (driverId != orderInfo.driverId) {
                                               driverId = orderInfo.driverId;
                                               findDriverInfo(driverId, orderInfo.clientLatitude,
                                                              orderInfo.clientLongitude);
                                           }

                                           setTimeout(findDJOrder, 1000);//请求成功间隔一秒再次请求
                                       }
                                       else if (orderInfo.status == 3 || orderInfo.status == 6) { //已完成
                                           //跳转完成界面
                                           alert('订单已完成');
                                           $location.path("/index");
                                       }

                                   }

                               }, function (error) {

                                   setTimeout(findDJOrder, 1000);//请求成功间隔一秒再次请求

                               });

                           }

                           /**
                            * 查询专车订单
                            */
                           function findZCOrder() {

                               var promise = zhuancheService.findOrder(cfg.sysKey,
                                                                       $routeParams.orderId);

                               promise.then(function (result) {

                                   if (result.success) {

                                       var orderInfo = result.data;

                                       $scope.bookTime = orderInfo.serverTime;
                                       $scope.beginAddress = orderInfo.startAddress;
                                       $scope.endAddress = orderInfo.endAddress;
                                       $scope.phone = orderInfo.passengerPhone;

                                       if (orderInfo.status == 6) { //已经销单
                                           //跳转到主页
                                           $location.path('/index');
                                           $location.replace();
                                       }
                                       else if (orderInfo.status == 0 || orderInfo.status == 1) {

                                           //跳转到下单成功界面
                                           $location.path('/success', {
                                               'orderId': $routeParams.orderId,
                                               'type': $routeParams.type
                                           });

                                       }
                                       else if (orderInfo.status == 2 || orderInfo.status == 3
                                                || orderInfo.status == 4) { //司机已接单

                                           //显示订单信息
                                           $scope.title = "司机正赶往您的预约地";
                                           $scope.acceptTime = orderInfo.acceptTime; //接单时间

                                           if (orderInfo.status == 3) {
                                               $scope.arriveTime = orderInfo.arriveTime;//到达预约地时间
                                               $scope.title = "司机已到达预约地";
                                               $scope.hideArrive = false;
                                           }

                                           if (orderInfo.status == 4) {
                                               $scope.startdriveTime = orderInfo.startdriveTime; //出发时间
                                               $scope.title = "司机正前往目的地";
                                               $scope.hideStartDrive = false;

                                               if (orderInfo.treatment) { //跳转支付界面
                                                   $location.path('/payment').search({
                                                                                         'orderId': $routeParams.orderId,
                                                                                         'type': $routeParams.type
                                                                                     });
                                                   return;
                                               }
                                           }

                                           //查询司机信息和位置信息
                                           if (driverId != orderInfo.employId) {
                                               driverId = orderInfo.employId;
                                               findDriverInfo(driverId, orderInfo.startLat,
                                                              orderInfo.startLng);
                                           }

                                           setTimeout(findZCOrder, 2000);//请求成功间隔一秒再次请求

                                       }
                                       else if (orderInfo.status == 5) { //已完成
                                           //跳转完成界面
                                           alert('订单已完成');
                                           $location.path("/index");
                                       }

                                   }

                               }, function (error) {
                                   setTimeout(findZCOrder, 1000);//请求成功间隔一秒再次请求
                               });

                           }

                           /**
                            * 查询专线订单
                            */
                           function findZXOneOrder() {

                               var promise = zhuanxianService.findZXOrder(cfg.sysKey,
                                                                          $routeParams.orderId);

                               promise.then(function (result) {

                                   if (result.code == 0) {

                                       var orderInfo = result.data;

                                       $scope.bookTime = orderInfo.serverTime;
                                       $scope.beginAddress = orderInfo.startAddress;
                                       $scope.endAddress = orderInfo.endAddress;
                                       $scope.phone = orderInfo.passengerPhone;

                                       if (orderInfo.status == 6) { //已经销单
                                           //跳转到主页
                                           $location.path('/index');
                                           $location.replace();
                                       }
                                       else if (orderInfo.status == 0 || orderInfo.status == 1) {

                                           //跳转到下单成功界面
                                           $location.path('/success', {
                                               'orderId': $routeParams.orderId,
                                               'type': $routeParams.type
                                           });

                                       }
                                       else if (orderInfo.status == 2 || orderInfo.status == 3
                                                || orderInfo.status == 4) { //司机已接单

                                           //显示订单信息
                                           $scope.title = "司机正赶往您的预约地";
                                           $scope.acceptTime = orderInfo.acceptTime; //接单时间

                                           if (orderInfo.status == 3) {
                                               $scope.arriveTime = orderInfo.arriveTime;//到达预约地时间
                                               $scope.title = "司机已到达预约地";
                                               $scope.hideArrive = false;
                                           }

                                           if (orderInfo.status == 4) {
                                               $scope.startdriveTime = orderInfo.startdriveTime; //出发时间
                                               $scope.title = "司机正前往目的地";
                                               $scope.hideStartDrive = false;

                                               if (orderInfo.treatment) { //跳转支付界面
                                                   $location.path('/payment').search({
                                                                                         'orderId': $routeParams.orderId,
                                                                                         'type': $routeParams.type
                                                                                     });
                                                   return;
                                               }
                                           }

                                           //查询司机信息和位置信息
                                           if (driverId != orderInfo.employId) {
                                               driverId = orderInfo.employId;
                                               findDriverInfo(driverId, orderInfo.startLat,
                                                              orderInfo.startLng);
                                           }

                                           setTimeout(findZXOneOrder, 2000);//请求成功间隔一秒再次请求

                                       }
                                       else if (orderInfo.status == 5) { //已完成
                                           //跳转完成界面
                                           alert('订单已完成');
                                           $location.path("/index");
                                       }

                                   }

                               }, function (error) {
                                   setTimeout(findZXOneOrder, 1000);//请求成功间隔一秒再次请求
                               });

                           }
                           
                           function findPTOneOrder() {

                               var promise = paotuiService.findOrder(cfg.sysKey,
                                                                          $routeParams.orderId);

                               promise.then(function (result) {
                                   if (result) {

                                       var orderInfo = result;

                                       $scope.bookTime = orderInfo.serverTime;
                                       $scope.beginAddress = orderInfo.startAddress;
                                       $scope.endAddress = orderInfo.endAddress;
                                       $scope.phone = orderInfo.passengerPhone;

                                       if (orderInfo.status == 5) { //已经销单
                                           //跳转到主页
                                           $location.path('/index');
                                           $location.replace();
                                       }
                                       else if (orderInfo.status == 0 || orderInfo.status == 1) {

                                           //跳转到下单成功界面
                                           $location.path('/success', {
                                               'orderId': $routeParams.orderId,
                                               'type': $routeParams.type
                                           });

                                       }
                                       else if (orderInfo.status == 2 || orderInfo.status == 3) { //司机已接单

                                           //显示订单信息
                                           $scope.title = "司机正赶往您的预约地";
                                           $scope.acceptTime = orderInfo.acceptTime; //接单时间

                                           /*if (orderInfo.status == 2) {
                                               $scope.arriveTime = orderInfo.arriveTime;//到达预约地时间
                                               $scope.title = "司机已到达预约地";
                                               $scope.hideArrive = false;
                                           }*/

                                           if (orderInfo.status == 3) {
                                               $scope.startdriveTime = orderInfo.startdriveTime; //出发时间
                                               $scope.title = "司机正前往目的地";
                                               $scope.hideStartDrive = false;

                                               if (orderInfo.treatment) { //跳转支付界面
                                                   $location.path('/payment').search({
                                                                                         'orderId': $routeParams.orderId,
                                                                                         'type': $routeParams.type
                                                                                     });
                                                   return;
                                               }
                                           }

                                           //查询司机信息和位置信息
                                           if (driverId != orderInfo.employId) {
                                               driverId = orderInfo.employId;
                                               findDriverInfo(driverId, orderInfo.startLat,
                                                              orderInfo.startLng);
                                           }

                                           setTimeout(findPTOneOrder, 2000);//请求成功间隔一秒再次请求

                                       }
                                       else if (orderInfo.status == 5) { //已完成
                                           //跳转完成界面
                                           alert('订单已完成');
                                           $location.path("/index");
                                       }

                                   }

                               }, function (error) {
                                   setTimeout(findPTOneOrder, 1000);//请求成功间隔一秒再次请求
                               });

                           }

                           /**
                            * 查询司机信息
                            *
                            * @param driverId 司机id
                            * @param lat  预约地纬度
                            * @param lng  预约地经度
                            */
                           function findDriverInfo(driverId, lat, lng) {

                               driverService.findDriver(cfg.sysKey, driverId)
                                   .then(function (result) {

                                       $scope.driverInfo = result;

                                       //计算预约地 与 司机位置距离

                                       locationService.geocoderFromBaidu({
                                                                             latitude: lat,
                                                                             longitude: lng
                                                                         }).then(function (data) {

                                           var addressComponent = data.addressComponent;
                                           var address = addressComponent.street
                                                         + addressComponent.street_number;
                                           $scope.currentAddress = address;

                                       });

                                   });

                           }

                           if ($routeParams.type == 'daijia') {

                               //查询订单信息
                               findDJOrder();

                           } else if ($routeParams.type == 'zhuanche') {

                               //查询专车订单
                               findZCOrder();
                           } else if ($routeParams.type == 'zhuanxian') {

                               //查询专线订单
                               findZXOneOrder();
                           } else if ($routeParams.type == 'paotui') {

                               //查询专线订单
                               findPTOneOrder();
                           }

                           //取消订单
                           $scope.cancel = function () {

                               if ($routeParams.type == 'daijia') {
                                   //取消代驾
                                   $location.path('/cancel').search({
                                                                        'orderId': $routeParams.orderId,
                                                                        'type': $routeParams.type
                                                                    });
                               }
                               else if ($routeParams.type == 'zhuanche') {
                                   //取消专车
                                   $location.path('/cancel').search({
                                                                        'orderId': $routeParams.orderId,
                                                                        'type': $routeParams.type
                                                                    });
                               } else if ($routeParams.type == 'paotui') {
                                   //取消专车
                                   $location.path('/cancel').search({
                                                                        'orderId': $routeParams.orderId,
                                                                        'type': $routeParams.type
                                                                    });
                               } else if ($routeParams.type == 'zhuanxian') {
                                   //取消专车
                                   $location.path('/cancel').search({
                                                                        'orderId': $routeParams.orderId,
                                                                        'type': $routeParams.type
                                                                    });
                               }
                           }
                       });

//时间选择
controllers.controller('DateTimePickerCtrl', function ($scope, $uibModalInstance) {

    var date = new Date();

    $scope.date = {
        year: date.getFullYear(),
        month: date.getMonth() + 1,
        day: date.getDate(),
        hour: date.getHours(),
        minute: date.getMinutes()
    };

    $scope.ok = function () {

        var date = new Date($scope.date.year, $scope.date.month
                                              - 1, $scope.date.day, $scope.date.hour, $scope.date.minute, 0);

        $uibModalInstance.close(date);
    }

    $scope.cancel = function () {
        $uibModalInstance.dismiss('cancel');
    }

    //分
    $scope.minuteAdd = function () {
        if ($scope.date.minute < 55) {
            $scope.date.minute = $scope.date.minute + 5;
        }
    }

    $scope.minuteSub = function () {
        if ($scope.date.minute > 0) {
            $scope.date.minute = $scope.date.minute - 5;
        }
    }

    //时
    $scope.hourAdd = function () {
        if ($scope.date.hour < 23) {
            $scope.date.hour++;
        }
    }

    $scope.hourSub = function () {
        if ($scope.date.hour > 0) {
            $scope.date.hour--;
        }
    }

    //年
    $scope.yearAdd = function () {

        $scope.date.year++;

        if ($scope.date.day > getLastDay()) {
            $scope.date.day = getLastDay();
        }
    }

    $scope.yearSub = function () {
        if ($scope.date.year > 2015) {
            $scope.date.year--;
        }

        if ($scope.date.day > getLastDay()) {
            $scope.date.day = getLastDay();
        }
    }

    //月
    $scope.monthAdd = function () {

        if ($scope.date.month < 12) {
            $scope.date.month++;
        }

        if ($scope.date.day > getLastDay()) {
            $scope.date.day = getLastDay();
        }
    }

    $scope.monthSub = function () {

        if ($scope.date.month > 1) {
            $scope.date.month--;
        }

        if ($scope.date.day > getLastDay()) {
            $scope.date.day = getLastDay();
        }
    }

    //日
    $scope.dayAdd = function () {

        if ($scope.date.day < getLastDay()) {
            $scope.date.day++;
        }

    }

    $scope.daySub = function () {
        if ($scope.date.day > 1) {
            $scope.date.day--;
        }
    }

    function getLastDay() {
        var time = new Date($scope.date.year, $scope.date.month, 1);
        return new Date(time.getTime() - 1000 * 60 * 60 * 24).getDate();
    }
});

//地址选择
controllers.controller('AddressPickerCtrl',
                       function ($scope, $rootScope, $uibModalInstance, locationService) {

                           $scope.items = [];

                           $scope.cancel = function () {
                               $uibModalInstance.dismiss('cancel');
                           }

                           $scope.select = function (pos) {

                               var poi = $scope.items[pos];

                               $uibModalInstance.close(poi);

                           }

                           $scope.$watch('address', function (newValue, oldValue, scope) {

                               var value = $.trim(newValue);

                               if (value.length > 2) {
                                   locationService.placeSearch(value,
                                                               $rootScope.currentLocation.city)
                                       .then(function (result) {
                                           if (result.data && result.data.status == 0) {
                                               $scope.items = result.data.results;
                                           }
                                       });
                               }
                           });
                       });

//提示消息框
controllers.controller('InfoCtrl', function ($scope, $uibModalInstance, content) {

    $scope.content = content;

    $scope.close = function () {
        $uibModalInstance.close();
    }
});

//支付界面
controllers.controller('PaymentCtrl',
                       function ($scope, $rootScope, $routeParams, $uibModal, $location,
                                 daijiaService, zhuancheService, zhuanxianService, gobalService,
                                 ngDialog,driverService, paotuiService) {
							ngDialog.closeAll();
                           var cfg = gobalService.config();

                           $scope.isSuccess = false;

                           /**
                            * 检查代驾订单是否被支付
                            */
                           function checkDaijiaPay() {
                               if (!$scope.isSuccess) {

                                   var promise = daijiaService.hasPayed(cfg.sysKey,
                                                                        $routeParams.orderId);

                                   promise.then(function (result) {
                                       if (result.code == 0) {

                                           if (result.data) { //已经被支付
                                               if (!$scope.isSuccess) {
                                                   //弹出支付提示
                                                   var modalInstance = $uibModal.open({
                                                                                          templateUrl: '/assets/v3/partials/info.html',
                                                                                          controller: 'InfoCtrl',
                                                                                          resolve: {
                                                                                              content: function () {
                                                                                                  return '订单支付成功';
                                                                                              }
                                                                                          }
                                                                                      });
                                                   //跳转主页面
//                                                       $location.path('/index');
                                                	   var orderDJ = daijiaService.findOrder(cfg.sysKey,
                                                               $routeParams.orderId);
        								                 orderDJ.then(function (fruit) {
        								                     var orderInfo = fruit.data;
        								                     var driverDJ = driverService.findDriver(
        								                         cfg.sysKey, orderInfo.driverId);
        								                     driverDJ.then(function (driverresult) {
        								                         $scope.driverInfo = driverresult;
        								                         $location.path('/assess').search({
        								                                                              'driverId': driverresult.employId,
        								                                                              'orderId': $routeParams.orderId,
        								                                                              'phone': orderInfo.clientPhone,
        								                                                              'type': 'daijia'
        								                                                          });
        								                     })
        								
        								                 }, function (error) {
        								
        								                     setTimeout($scope.into, 5000);//请求成功间隔一秒再次请求
        								
        								                 });
                                                	   
                                                	   
                                               }

                                               $scope.isSuccess = true; //已经支付成功

                                           } else {
                                               setTimeout(checkDaijiaPay, 2000);//请求成功间隔2秒再次请求
                                           }

                                       } else {
                                           setTimeout(checkDaijiaPay, 2000);//请求成功间隔2秒再次请求
                                       }
                                   }, function (error) {

                                       setTimeout(checkDaijiaPay, 2000);//请求成功间隔2秒再次请求

                                   });

                               }

                           }

                           function checkZhuanchePay() {
                               if (!$scope.isSuccess) {

                                   var promise = zhuancheService.hasPayed(cfg.sysKey,
                                                                          $routeParams.orderId);

                                   promise.then(function (result) {
                                       if (result.code == 0) {

                                           if (result.data) { //已经被支付
                                               if (!$scope.isSuccess) {
                                                   //弹出支付提示
                                                   var modalInstance = $uibModal.open({
                                                                                          templateUrl: '/assets/v3/partials/info.html',
                                                                                          controller: 'InfoCtrl',
                                                                                          resolve: {
                                                                                              content: function () {
                                                                                                  return '订单支付成功';
                                                                                              }
                                                                                          }
                                                                                      });
                                                   //跳转主页面
//                                                     $location.path('/index');
                                              	   var orderDJ = zhuancheService.findOrder(cfg.sysKey,
                                                             $routeParams.orderId);
      								                 orderDJ.then(function (fruit) {
      								                     var orderInfo = fruit.data;
      								                     var driverDJ = driverService.findDriver(
      								                         cfg.sysKey, orderInfo.employId);
      								                     driverDJ.then(function (driverresult) {
      								                         $scope.driverInfo = driverresult;
      								                         $location.path('/assess').search({
      								                                                              'driverId': driverresult.employId,
      								                                                              'orderId': $routeParams.orderId,
      								                                                              'type': 'zhuanche'
      								                                                          });
      								                     })
      								
      								                 }, function (error) {
      								
      								                     setTimeout($scope.into, 5000);//请求成功间隔一秒再次请求
      								
      								                 });
                                                	   
                                                	   
                                               }

                                               $scope.isSuccess = true; //已经支付成功

                                           } else {
                                               setTimeout(checkZhuanchePay, 2000);//请求成功间隔2秒再次请求
                                           }

                                       } else {
                                           setTimeout(checkZhuanchePay, 2000);//请求成功间隔2秒再次请求
                                       }
                                   }, function (error) {

                                       setTimeout(checkZhuanchePay, 2000);//请求成功间隔2秒再次请求

                                   });

                               }

                           }

                           function checkZhuanxianPay() {
                               if (!$scope.isSuccess) {

                                   var promise = zhuanxianService.hasPayed(cfg.sysKey,
                                                                           $routeParams.orderId);

                                   promise.then(function (result) {
                                       if (result.code == 0) {

                                           if (result.data) { //已经被支付
                                               if (!$scope.isSuccess) {
                                                   //弹出支付提示
                                                   var modalInstance = $uibModal.open({
                                                                                          templateUrl: '/assets/v3/partials/info.html',
                                                                                          controller: 'InfoCtrl',
                                                                                          resolve: {
                                                                                              content: function () {
                                                                                                  return '订单支付成功';
                                                                                              }
                                                                                          }
                                                                                      });
                                                   //跳转主页面
//                                                     $location.path('/index');
                                              	   var orderDJ = zhuanxianService.findZXOrder(cfg.sysKey,
                                                             $routeParams.orderId);
      								                 orderDJ.then(function (fruit) {
      								                	if (fruit.code == 0) {
      								                     var orderInfo = fruit.data;
      								                     var driverDJ = driverService.findDriver(
      								                         cfg.sysKey, orderInfo.employId);
      								                     driverDJ.then(function (driverresult) {
      								                         $scope.driverInfo = driverresult;
      								                         $location.path('/assess').search({
      								                                                              'driverId': driverresult.employId,
      								                                                              'orderId': $routeParams.orderId,
      								                                                              'type': 'zhuanxian'
      								                                                          });
      								                     })
      								                	}
      								
      								                 }, function (error) {
      								
      								                     setTimeout($scope.into, 5000);//请求成功间隔一秒再次请求
      								
      								                 });
                                              	   
                                              	   
                                                 
                                                	   
                                                	   
                                               }

                                               $scope.isSuccess = true; //已经支付成功

                                           } else {
                                               setTimeout(checkZhuanxianPay, 2000);//请求成功间隔2秒再次请求
                                           }

                                       } else {
                                           setTimeout(checkZhuanxianPay, 2000);//请求成功间隔2秒再次请求
                                       }
                                   }, function (error) {

                                       setTimeout(checkZhuanxianPay, 2000);//请求成功间隔2秒再次请求

                                   });

                               }

                           }

                           function checkErrandPay() {
                               if (!$scope.isSuccess) {

                                   var promise = paotuiService.hasPayed(cfg.sysKey,
                                                                        $routeParams.orderId);

                                   promise.then(function (result) {
                                       if (result.code == 0) {

                                           if (result.data) { //已经被支付
                                               if (!$scope.isSuccess) {
                                                   //弹出支付提示
                                                   var modalInstance = $uibModal.open({
                                                                                          templateUrl: '/assets/v3/partials/info.html',
                                                                                          controller: 'InfoCtrl',
                                                                                          resolve: {
                                                                                              content: function () {
                                                                                                  return '订单支付成功';
                                                                                              }
                                                                                          }
                                                                                      });
                                                   //跳转主页面
                                                   modalInstance.result.then(function (res) {
//                                                     $location.path('/index');
                                              	   var orderDJ = paotuiService.findOrder(cfg.sysKey,
                                                             $routeParams.orderId);
      								                 orderDJ.then(function (fruit) {
      								                     var orderInfo = fruit;
      								                     var driverDJ = driverService.findDriver(
      								                         cfg.sysKey, orderInfo.employId);
      								                     driverDJ.then(function (driverresult) {
      								                         $scope.driverInfo = driverresult;
      								                         $location.path('/assess').search({
      								                                                              'driverId': driverresult.employId,
      								                                                              'orderId': $routeParams.orderId,
      								                                                              'type': 'paotui'
      								                                                          });
      								                     })
      								
      								                 }, function (error) {
      								
      								                     setTimeout($scope.into, 5000);//请求成功间隔一秒再次请求
      								
      								                 });
                                              	   
                                              	   
                                                 
                                                	   
                                                	   
                                                   });
                                               }

                                               $scope.isSuccess = true; //已经支付成功

                                           } else {
                                               setTimeout(checkErrandPay, 2000);//请求成功间隔2秒再次请求
                                           }

                                       } else {
                                           setTimeout(checkErrandPay, 2000);//请求成功间隔2秒再次请求
                                       }
                                   }, function (error) {

                                       setTimeout(checkErrandPay, 2000);//请求成功间隔2秒再次请求

                                   });

                               }

                           }

                           if ($routeParams.type == 'daijia') {

                               //检查代驾订单是否已经被支付
                               checkDaijiaPay();

                               //获取支付信息
                               daijiaService.prepay(cfg.sysKey, $routeParams.orderId)
                                   .then(function (result) {

                                       if (result.code == 0) {
                                           var payInfo = result.data;
                                           $scope.payInfo = payInfo;
                                           $scope.totalFee = payInfo.realCash + payInfo.guoluMoney;

                                       } else {
                                           alert(result.msg);
                                       }

                                   }, function (error) {
                                       alert('获取信息失败,请刷新页面重试');
                                   });

                           } else if ($routeParams.type == 'zhuanche') {

                               //查询专车订单
                               checkZhuanchePay();

                               //获取支付信息
                               zhuancheService.prepay(cfg.sysKey, $routeParams.orderId)
                                   .then(function (result) {

                                       if (result.code == 0) {
                                           var payInfo = result.data;
                                           $scope.payInfo = payInfo;
                                           $scope.totalFee =
                                               payInfo.realCash + payInfo.guoluMoney;

                                       } else {
                                           alert(result.msg);
                                       }

                                   }, function (error) {
                                       alert('获取信息失败,请刷新页面重试');
                                   });

                           } else if ($routeParams.type == 'paotui') {

                               //查询跑腿订单
                               checkErrandPay();

                               //获取支付信息
                               paotuiService.prepay(cfg.sysKey, $routeParams.orderId)
                                   .then(function (result) {

                                       if (result.code == 0) {
                                           var payInfo = result.data;
                                           $scope.payInfo = payInfo;
                                           $scope.totalFee =
                                               payInfo.realCash + payInfo.guoluMoney;

                                       } else {
                                           alert(result.msg);
                                       }

                                   }, function (error) {
                                       alert('获取信息失败,请刷新页面重试');
                                   });

                           } else if ($routeParams.type == 'zhuanxian') {

                               //查询专线订单
                               checkZhuanxianPay();

                               //获取支付信息
                               zhuanxianService.prepay(cfg.sysKey, $routeParams.orderId)
                                   .then(function (result) {

                                       if (result.code == 0) {
                                           var payInfo = result.data;
                                           $scope.payInfo = payInfo;
                                           $scope.totalFee =
                                               payInfo.realCash + payInfo.guoluMoney;

                                       } else {
                                           alert(result.msg);
                                       }

                                   }, function (error) {
                                       alert('获取信息失败,请刷新页面重试');
                                   });

                           }

                           function payForDaijia() {
                               if ($scope.payType == 'weixin') { //微信

                                   daijiaService.doPayForWx(cfg.sysKey, $routeParams.orderId,
                                		   $rootScope.openId, cfg.appId)
                                       .then(function (result) {
                                           wx.config({
                                                         debug: false,
                                                         appId: cfg.appId,
                                                         timestamp: result.timestamp,
                                                         nonceStr: result.nonceStr,
                                                         signature: result.signature,
                                                         jsApiList: ['chooseWXPay']
                                                     });

                                           wx.ready(function () {
                                               wx.chooseWXPay({
                                                                  timestamp: result.timestamp,
                                                                  nonceStr: result.nonceStr,
                                                                  package: result.package,
                                                                  signType: 'MD5',
                                                                  paySign: result.paySign,
                                                                  success: function (res) {
                                                                      // 支付成功后的回调函数
                                                                      if (res.errMsg
                                                                          == 'chooseWXPay:ok') {
                                                                          if (!$scope.isSuccess) {
                                                                              //弹出支付提示
                                                                              var modalInstance = $uibModal.open(
                                                                                  {
                                                                                      templateUrl: '/assets/v4/partials/info.html',
                                                                                      controller: 'InfoCtrl',
                                                                                      resolve: {
                                                                                          content: function () {
                                                                                              return '订单支付成功';
                                                                                          }
                                                                                      }
                                                                                  });
                                                                              //跳转主页面
                                                                              modalInstance.close(
                                                                                  true);
//                                  $location.path('/index');
                                                                              var orderDJ = daijiaService.findOrder(
                                                                                  cfg.sysKey,
                                                                                  $routeParams.orderId);
                                                                              orderDJ.then(
                                                                                  function (fruit) {
                                                                                      if (fruit.success) {
                                                                                          var orderInfo = fruit.data;
                                                                                          var driverDJ = driverService.findDriver(
                                                                                              cfg.sysKey,
                                                                                              orderInfo.driverId);
                                                                                          driverDJ.then(
                                                                                              function (result) {
                                                                                                  $scope.driverInfo =
                                                                                                      result;
                                                                                                  $location.path(
                                                                                                      '/assess')
                                                                                                      .search(
                                                                                                          {
                                                                                                              'phone': orderInfo.clientPhone,
                                                                                                              'driverId': result.employId,
                                                                                                              'orderId': $routeParams.orderId,
                                                                                                              'type': 'daijia'
                                                                                                          });
                                                                                              })
                                                                                      }

                                                                                  },
                                                                                  function (error) {

                                                                                      setTimeout(
                                                                                          $scope.into,
                                                                                          5000);//请求成功间隔一秒再次请求

                                                                                  });
                                                                          }
                                                                          $scope.isSuccess = true; //已经支付成功
                                                                      } else if (res.errMsg
                                                                                 == 'chooseWXPay:cancel') {
                                                                          alert('您取消了微信支付');
                                                                      } else {
                                                                          alert(res.errMsg);
                                                                      }
                                                                  }
                                                              });
                                           });

                                       });

                               }
                               else if ($scope.payType == 'balance' || $scope.payType == 'sign') { //余额 或者 //签单
                            	   
                            	   $("#dopay").attr("disabled",true);

                                   daijiaService.doPay(cfg.sysKey, $routeParams.orderId,
                                                       $scope.payType).then(function (result) {
                                       if (result.code == 0) {
                                           //弹出支付提示
                                           if (!$scope.isSuccess) {

                                               $scope.isSuccess = true;

                                               var modalInstance = $uibModal.open({
                                                                                      templateUrl: '/assets/v4/partials/info.html',
                                                                                      overlay: true,
                                                                                      showClose: true,
                                                                                      controller: 'InfoCtrl',
                                                                                      resolve: {
                                                                                          content: function () {
                                                                                              return '订单支付成功';
                                                                                          }
                                                                                      }
                                                                                  });
                                               //跳转主页面

                                               modalInstance.close(true);
//                        $location.path('/index');
                                               var orderDJ = daijiaService.findOrder(cfg.sysKey,
                                                                                     $routeParams.orderId);
                                               orderDJ.then(function (fruit) {
                                                   if (fruit.success) {
                                                       var orderInfo = fruit.data;
                                                       var driverDJ = driverService.findDriver(
                                                           cfg.sysKey, orderInfo.driverId);
                                                       driverDJ.then(function (result) {
                                                           $scope.driverInfo = result;
                                                           $location.path('/assess').search({
                                                                                                'phone': orderInfo.clientPhone,
                                                                                                'driverId': result.employId,
                                                                                                'orderId': $routeParams.orderId,
                                                                                                'type': 'daijia'
                                                                                            });
                                                       })
                                                   }

                                               }, function (error) {

                                                   setTimeout($scope.into, 5000);//请求成功间隔一秒再次请求

                                               });

                                           }
                                       } else {
                                    	   $("#dopay").attr("disabled",false);
                                    	   alert(result.message);
                                    	   if(result.code== -78){
                                    		   var orderDJ = daijiaService.findOrder(cfg.sysKey,
                                                       $routeParams.orderId);
								                 orderDJ.then(function (fruit) {
								                     if (fruit.success) {
								                         var orderInfo = fruit.data;
								                         var driverDJ = driverService.findDriver(
								                             cfg.sysKey, orderInfo.driverId);
								                         driverDJ.then(function (result) {
								                             $scope.driverInfo = result;
								                             $location.path('/assess').search({
								                                                                  'phone': orderInfo.clientPhone,
								                                                                  'driverId': result.employId,
								                                                                  'orderId': $routeParams.orderId,
								                                                                  'type': 'daijia'
								                                                              });
								                         })
								                     }
								
								                 }, function (error) {
								
								                     setTimeout($scope.into, 5000);//请求成功间隔一秒再次请求
								
								                 });
                                    	   }
                                    	   
                                           
                                       }

                                   }, function (error) {
                                	   $("#dopay").attr("disabled",false);
                                       alert('结算失败,请稍后再试');
                                   });

                               }
                           }

                           function payForZhuanche() {

                               if ($scope.payType == 'weixin') { //微信

                                   zhuancheService.doPayForWx(cfg.sysKey, $routeParams.orderId,
                                                              $rootScope.openId, cfg.appId)
                                       .then(function (result) {

                                           wx.config({
                                                         debug: false,
                                                         appId: cfg.appId,
                                                         timestamp: result.timestamp,
                                                         nonceStr: result.nonceStr,
                                                         signature: result.signature,
                                                         jsApiList: ['chooseWXPay']
                                                     });

                                           wx.ready(function () {
                                               wx.chooseWXPay({
                                                                  timestamp: result.timestamp,
                                                                  nonceStr: result.nonceStr,
                                                                  package: result.package,
                                                                  signType: 'MD5',
                                                                  paySign: result.paySign,
                                                                  success: function (res) {
                                                                      // 支付成功后的回调函数
                                                                      if (res.errMsg
                                                                          == 'chooseWXPay:ok') {
                                                                          if (!$scope.isSuccess) {
                                                                              //弹出支付提示
                                                                              var modalInstance = $uibModal.open(
                                                                                  {
                                                                                      templateUrl: '/assets/v4/partials/info.html',
                                                                                      controller: 'InfoCtrl',
                                                                                      resolve: {
                                                                                          content: function () {
                                                                                              return '订单支付成功';
                                                                                          }
                                                                                      }
                                                                                  });
                                                                              //跳转主页面
                                                                              modalInstance.close(
                                                                                  true);
//                                  $location.path('/index');
                                                                              var orderDJ = zhuancheService.findOrder(
                                                                                  cfg.sysKey,
                                                                                  $routeParams.orderId);
                                                                              orderDJ.then(
                                                                                  function (fruit) {
                                                                                      if (fruit.success) {
                                                                                          var orderInfo = fruit.data;
                                                                                          var driverDJ = driverService.findDriver(
                                                                                              cfg.sysKey,
                                                                                              orderInfo.employId);
                                                                                          driverDJ.then(
                                                                                              function (result) {
                                                                                                  $scope.driverInfo =
                                                                                                      result;
                                                                                                  $location.path(
                                                                                                      '/assess')
                                                                                                      .search(
                                                                                                          {
                                                                                                              'phone': orderInfo.clientPhone,
                                                                                                              'driverId': result.employId,
                                                                                                              'orderId': $routeParams.orderId,
                                                                                                              'type': 'zhuanche'
                                                                                                          });
                                                                                              })
                                                                                      }

                                                                                  },
                                                                                  function (error) {

                                                                                      setTimeout(
                                                                                          $scope.into,
                                                                                          5000);//请求成功间隔一秒再次请求

                                                                                  });
                                                                          }
                                                                          $scope.isSuccess = true; //已经支付成功
                                                                      } else if (res.errMsg
                                                                                 == 'chooseWXPay:cancel') {
                                                                          alert('您取消了微信支付');
                                                                      } else {
                                                                          alert(res.errMsg);
                                                                      }
                                                                  }
                                                              });
                                           });

                                       });

                               }
                               else if ($scope.payType == 'balance' || $scope.payType == 'sign') { //余额 或者 //签单
                            	   
                            	   $("#dopay").attr("disabled",true);

                                   zhuancheService.doPay(cfg.sysKey, $routeParams.orderId,
                                                         $scope.payType).then(function (result) {

                                       if (result.code == 0) {
                                           //弹出支付提示
                                           if (!$scope.isSuccess) {

                                               $scope.isSuccess = true;

                                               var modalInstance = $uibModal.open({
                                                                                      templateUrl: '/assets/v4/partials/info.html',
                                                                                      controller: 'InfoCtrl',
                                                                                      resolve: {
                                                                                          content: function () {
                                                                                              return '订单支付成功';
                                                                                          }
                                                                                      }
                                                                                  });
                                               //跳转主页面
                                               modalInstance.close(true);
//                      $location.path('/index');
                                               var orderDJ = zhuancheService.findOrder(cfg.sysKey,
                                                                                       $routeParams.orderId);
                                               orderDJ.then(function (fruit) {
                                                   if (fruit.success) {
                                                       var orderInfo = fruit.data;
                                                       var driverDJ = driverService.findDriver(
                                                           cfg.sysKey, orderInfo.employId);
                                                       driverDJ.then(function (result) {
                                                           $scope.driverInfo = result;
                                                           $location.path('/assess').search({
                                                                                                'driverId': result.employId,
                                                                                                'orderId': $routeParams.orderId,
                                                                                                'type': 'zhuanche'
                                                                                            });
                                                       })
                                                   }

                                               }, function (error) {

                                                   setTimeout($scope.into, 5000);//请求成功间隔一秒再次请求

                                               });
                                           }
                                       } else {
                                    	   $("#dopay").attr("disabled",false);
                                           alert(result.message);
                                           if(result.code== -78){
                                        	   var orderDJ = zhuancheService.findOrder(cfg.sysKey,
                                                       $routeParams.orderId);
    								           orderDJ.then(function (fruit) {
    								               if (fruit.success) {
    								                   var orderInfo = fruit.data;
    								                   var driverDJ = driverService.findDriver(
    								                       cfg.sysKey, orderInfo.employId);
    								                   driverDJ.then(function (result) {
    								                       $scope.driverInfo = result;
    								                       $location.path('/assess').search({
    								                                                            'driverId': result.employId,
    								                                                            'orderId': $routeParams.orderId,
    								                                                            'type': 'zhuanche'
    								                                                        });
    								                   })
    								               }
    								
    								           }, function (error) {
    								
    								               setTimeout($scope.into, 5000);//请求成功间隔一秒再次请求
    								
    								           });
                                           }
                                           
                                       }

                                   }, function (error) {
                                	   
                                	   $("#dopay").attr("disabled",false);
                                	   
                                       alert('结算失败,请稍后再试');
                                   });

                               }
                           }

                           function payForErrand() {

                               if ($scope.payType == 'weixin') { //微信

                                   paotuiService.doPayForWx(cfg.sysKey, $routeParams.orderId,
                                                            $rootScope.openId, cfg.appId)
                                       .then(function (result) {

                                           wx.config({
                                                         debug: false,
                                                         appId: cfg.appId,
                                                         timestamp: result.timestamp,
                                                         nonceStr: result.nonceStr,
                                                         signature: result.signature,
                                                         jsApiList: ['chooseWXPay']
                                                     });

                                           wx.ready(function () {
                                               wx.chooseWXPay({
                                                                  timestamp: result.timestamp,
                                                                  nonceStr: result.nonceStr,
                                                                  package: result.package,
                                                                  signType: 'MD5',
                                                                  paySign: result.paySign,
                                                                  success: function (res) {
                                                                      // 支付成功后的回调函数
                                                                      if (res.errMsg
                                                                          == 'chooseWXPay:ok') {
                                                                          if (!$scope.isSuccess) {
                                                                              //弹出支付提示
                                                                              var modalInstance = $uibModal.open(
                                                                                  {
                                                                                      templateUrl: '/assets/v4/partials/info.html',
                                                                                      controller: 'InfoCtrl',
                                                                                      resolve: {
                                                                                          content: function () {
                                                                                              return '订单支付成功';
                                                                                          }
                                                                                      }
                                                                                  });
                                                                              //跳转主页面
                                                                              modalInstance.close(
                                                                                  true);
//                                  $location.path('/index');
                                                                              var orderDJ = paotuiService.findOrder(
                                                                                  cfg.sysKey,
                                                                                  $routeParams.orderId);
                                                                              orderDJ.then(
                                                                                  function (fruit) {
                                                                                      if (fruit.success) {
                                                                                          var orderInfo = fruit;
                                                                                          var driverDJ = driverService.findDriver(
                                                                                              cfg.sysKey,
                                                                                              orderInfo.employId);
                                                                                          driverDJ.then(
                                                                                              function (result) {
                                                                                                  $scope.driverInfo =
                                                                                                      result;
                                                                                                  $location.path(
                                                                                                      '/assess')
                                                                                                      .search(
                                                                                                          {
                                                                                                              'phone': orderInfo.clientPhone,
                                                                                                              'driverId': result.employId,
                                                                                                              'orderId': $routeParams.orderId,
                                                                                                              'type': 'paotui'
                                                                                                          });
                                                                                              })
                                                                                      }

                                                                                  },
                                                                                  function (error) {

                                                                                      setTimeout(
                                                                                          $scope.into,
                                                                                          5000);//请求成功间隔一秒再次请求

                                                                                  });
                                                                          }
                                                                          $scope.isSuccess = true; //已经支付成功
                                                                      } else if (res.errMsg
                                                                                 == 'chooseWXPay:cancel') {
                                                                          alert('您取消了微信支付');
                                                                      } else {
                                                                          alert(res.errMsg);
                                                                      }
                                                                  }
                                                              });
                                           });

                                       });

                               }
                               else if ($scope.payType == 'balance' || $scope.payType == 'sign') { //余额 或者 //签单
                            	   
                            	   $("#dopay").attr("disabled",true);
                            	   
                                   paotuiService.doPay(cfg.sysKey, $routeParams.orderId,
                                                       $scope.payType).then(function (result) {

                                       if (result.code == 0) {
                                           //弹出支付提示
                                           if (!$scope.isSuccess) {

                                               $scope.isSuccess = true;

                                               var modalInstance = $uibModal.open({
                                                                                      templateUrl: '/assets/v4/partials/info.html',
                                                                                      controller: 'InfoCtrl',
                                                                                      resolve: {
                                                                                          content: function () {
                                                                                              return '订单支付成功';
                                                                                          }
                                                                                      }
                                                                                  });
                                               //跳转主页面
                                               modalInstance.close(true);
//                      $location.path('/index');
                                               var orderDJ = paotuiService.findOrder(cfg.sysKey,
                                                                                     $routeParams.orderId);
                                               orderDJ.then(function (fruit) {
                                                   var orderInfo = fruit;
                                                   var driverDJ = driverService.findDriver(
                                                       cfg.sysKey, orderInfo.employId);
                                                   driverDJ.then(function (result) {
                                                       $scope.driverInfo = result;
                                                       $location.path('/assess').search({
                                                                                            'driverId': result.employId,
                                                                                            'orderId': $routeParams.orderId,
                                                                                            'type': 'paotui'
                                                                                        });
                                                   })

                                               }, function (error) {

                                                   setTimeout($scope.into, 5000);//请求成功间隔一秒再次请求

                                               });
                                           }
                                       } else {
                                    	   $("#dopay").attr("disabled",false);
                                           alert(result.message);
                                           if(result.code == -78){
                                        	   var orderDJ = paotuiService.findOrder(cfg.sysKey,
                                                       $routeParams.orderId);
								                 orderDJ.then(function (fruit) {
								                     var orderInfo = fruit;
								                     var driverDJ = driverService.findDriver(
								                         cfg.sysKey, orderInfo.employId);
								                     driverDJ.then(function (result) {
								                         $scope.driverInfo = result;
								                         $location.path('/assess').search({
								                                                              'driverId': result.employId,
								                                                              'orderId': $routeParams.orderId,
								                                                              'type': 'paotui'
								                                                          });
								                     })
								
								                 }, function (error) {
								
								                     setTimeout($scope.into, 5000);//请求成功间隔一秒再次请求
								
								                 });
                                        	   
                                           }
                                           
                                       }

                                   }, function (error) {
                                	   $("#dopay").attr("disabled",false);
                                       alert('结算失败,请稍后再试');
                                   });

                               }
                           }

                           function payForZhuanxian() {

                               if ($scope.payType == 'weixin') { //微信

                                   zhuanxianService.doPayForWx(cfg.sysKey, $routeParams.orderId,
                                		   $rootScope.openId,cfg.appId).then(function (result) {

                                       wx.config({
                                                     debug: false,
                                                     appId: cfg.appId,
                                                     timestamp: result.timestamp,
                                                     nonceStr: result.nonceStr,
                                                     signature: result.signature,
                                                     jsApiList: ['chooseWXPay']
                                                 });

                                       wx.ready(function () {
                                           wx.chooseWXPay({
                                                              timestamp: result.timestamp,
                                                              nonceStr: result.nonceStr,
                                                              package: result.package,
                                                              signType: 'MD5',
                                                              paySign: result.paySign,
                                                              success: function (res) {
                                                                  // 支付成功后的回调函数
                                                                  if (res.errMsg
                                                                      == 'chooseWXPay:ok') {
                                                                      if (!$scope.isSuccess) {
                                                                          //弹出支付提示
                                                                          var modalInstance = $uibModal.open(
                                                                              {
                                                                                  templateUrl: '/assets/v4/partials/info.html',
                                                                                  controller: 'InfoCtrl',
                                                                                  resolve: {
                                                                                      content: function () {
                                                                                          return '订单支付成功';
                                                                                      }
                                                                                  }
                                                                              });
                                                                          //跳转主页面
                                                                          modalInstance.close(true);
//                                  $location.path('/index');
                                                                          var orderDJ = zhuanxianService.findZXOrder(
                                                                              cfg.sysKey,
                                                                              $routeParams.orderId);
                                                                          orderDJ.then(
                                                                              function (fruit) {
                                                                                  if (fruit.code
                                                                                      == 0) {
                                                                                      var orderInfo = fruit.data;
                                                                                      var driverDJ = driverService.findDriver(
                                                                                          cfg.sysKey,
                                                                                          orderInfo.employId);
                                                                                      driverDJ.then(
                                                                                          function (result) {
                                                                                              $scope.driverInfo =
                                                                                                  result;
                                                                                              $location.path(
                                                                                                  '/assess')
                                                                                                  .search(
                                                                                                      {
                                                                                                          'phone': orderInfo.clientPhone,
                                                                                                          'driverId': result.employId,
                                                                                                          'orderId': $routeParams.orderId,
                                                                                                          'type': 'zhuanxian'
                                                                                                      });
                                                                                          })
                                                                                  }

                                                                              }, function (error) {

                                                                                  setTimeout(
                                                                                      $scope.into,
                                                                                      5000);//请求成功间隔一秒再次请求

                                                                              });
                                                                      }
                                                                      $scope.isSuccess = true; //已经支付成功
                                                                  } else if (res.errMsg
                                                                             == 'chooseWXPay:cancel') {
                                                                      alert('您取消了微信支付');
                                                                  } else {
                                                                      alert(res.errMsg);
                                                                  }
                                                              }
                                                          });
                                       });

                                   });

                               }
                               else if ($scope.payType == 'balance' || $scope.payType == 'sign') { //余额 或者 //签单
                            	   
                            	   $("#dopay").attr("disabled",true);

                                   zhuanxianService.doPay(cfg.sysKey, $routeParams.orderId,
                                                          $scope.payType).then(function (result) {

                                       if (result.code == 0) {
                                           //弹出支付提示
                                           if (!$scope.isSuccess) {

                                               $scope.isSuccess = true;

                                               var modalInstance = $uibModal.open({
                                                                                      templateUrl: '/assets/v4/partials/info.html',
                                                                                      controller: 'InfoCtrl',
                                                                                      resolve: {
                                                                                          content: function () {
                                                                                              return '订单支付成功';
                                                                                          }
                                                                                      }
                                                                                  });
                                               //跳转主页面
                                               modalInstance.close(true);
//                      $location.path('/index');
                                               var orderDJ = zhuanxianService.findZXOrder(
                                                   cfg.sysKey, $routeParams.orderId);
                                               orderDJ.then(function (fruit) {
                                                   if (fruit.code == 0) {
                                                       var orderInfo = fruit.data;
                                                       var driverDJ = driverService.findDriver(
                                                           cfg.sysKey, orderInfo.employId);
                                                       driverDJ.then(function (result) {
                                                           $scope.driverInfo = result;
                                                           $location.path('/assess').search({
                                                                                                'driverId': result.employId,
                                                                                                'orderId': $routeParams.orderId,
                                                                                                'type': 'zhuanxian'
                                                                                            });
                                                       })
                                                   }

                                               }, function (error) {

                                                   setTimeout($scope.into, 5000);//请求成功间隔一秒再次请求

                                               });
                                           }
                                       } else {
                                    	   $("#dopay").attr("disabled",false);
                                           alert(result.message);
                                           if(result.code == -78){
                                        	   var orderDJ = zhuanxianService.findZXOrder(
                                                       cfg.sysKey, $routeParams.orderId);
                                                   orderDJ.then(function (fruit) {
                                                       if (fruit.code == 0) {
                                                           var orderInfo = fruit.data;
                                                           var driverDJ = driverService.findDriver(
                                                               cfg.sysKey, orderInfo.employId);
                                                           driverDJ.then(function (result) {
                                                               $scope.driverInfo = result;
                                                               $location.path('/assess').search({
                                                                                                    'driverId': result.employId,
                                                                                                    'orderId': $routeParams.orderId,
                                                                                                    'type': 'zhuanxian'
                                                                                                });
                                                           })
                                                       }

                                                   }, function (error) {

                                                       setTimeout($scope.into, 5000);//请求成功间隔一秒再次请求

                                                   });
                                           }
                                       }

                                   }, function (error) {
                                	   $("#dopay").attr("disabled",false);
                                       alert('结算失败,请稍后再试');
                                   });

                               }
                           }

                           $scope.dopay = function () {

                               if ($routeParams.type == 'daijia') {

                                   payForDaijia();

                               } else if ($routeParams.type == 'zhuanche') {

                                   payForZhuanche();
                               } else if ($routeParams.type == 'paotui') {

                                   payForErrand();
                               } else if ($routeParams.type == 'zhuanxian') {

                                   payForZhuanxian();
                               }

                           }

                       });

//登录界面
controllers.controller('LoginCtrl',
                       function ($scope, $rootScope, $sce, $routeParams, $interval, $location,
                                 gobalService, userService, locationService) {

							
                           var nav = angular.element('nav');

                           if (nav) {
                               nav.hide();
                           }

                           var refer = $routeParams.refer;
                           if (!refer) {
                               $location.path('/index');
                           }

                           var cfg = gobalService.config();

                           $scope.btn = $sce.trustAsHtml('获取验证码');
                           $scope.btnDisabled = false;

                           var promise = locationService.locateMe($rootScope);

                           promise.then(function (locationInfo) {
                               /**
                                * 发送验证码
                                */
                               $scope.sendVCode = function () {

                                   if (!$scope.phone) {
                                       alert('请输入手机号码');
                                       return;
                                   }

                                   $scope.btnDisabled = true;

                                   userService.sendVCode(cfg.sysKey, $scope.phone)
                                       .then(function (result) {

                                           if (result.success) {

                                               $scope.timecount = 120;

                                               var interval = $interval(function () {

                                                   $scope.timecount--;

                                                   $scope.btn =
                                                       $sce.trustAsHtml($scope.timecount + 's');

                                                   if ($scope.timecount == 0) {
                                                       $interval.cancel(interval);
                                                       $scope.btn = $sce.trustAsHtml('获取验证码');
                                                       $scope.btnDisabled = false;
                                                   }

                                               }, 1000);

                                           } else if (result.object) {

                                               $scope.timecount = 120 - parseInt(result.object);

                                               var interval = $interval(function () {

                                                   $scope.timecount--;

                                                   $scope.btn =
                                                       $sce.trustAsHtml($scope.timecount + 's');

                                                   if ($scope.timecount == 0) {
                                                       $interval.cancel(interval);
                                                       $scope.btn = $sce.trustAsHtml('获取验证码');
                                                       $scope.btnDisabled = false;
                                                   }

                                               }, 1000)
                                           } else {
                                               alert('验证码发送失败,请稍候再试');
                                               $scope.btnDisabled = false;
                                           }

                                       }, function (error) {
                                           alert('验证码发送失败,请稍候再试');
                                           $scope.btnDisabled = false;
                                       });
                               }

                               /**
                                * 执行登录
                                */
                               $scope.submit = function () {

                                   if (!$scope.phone) {
                                       alert('请输入手机号码');
                                       return;
                                   }

                                   if (!$scope.vcode) {
                                       alert('请输入验证码');
                                       return;
                                   }

                                   var promise = userService.checkCode(cfg.appId, cfg.sysKey,
                                                                       $scope.phone, $scope.vcode,
                                                                       $rootScope.openId,
                                                                       locationInfo.city);

                                   promise.then(function (result) {

                                       if (result.success) {
                                           $rootScope.passengerPhone = result.passengerPhone;
                                           $rootScope.passengerId = result.passengerId;
                                           $location.path(refer);

                                       } else {
                                           alert('登录失败,请稍候再试');
                                       }

                                   }, function (error) {
                                       alert('登录失败,请稍候再试');
                                   });
                               }

                           });

                       });

//服务协议
controllers.controller('AgreementCtrl',
                       function ($scope, $rootScope, $sce, $window, userService,ngDialog, gobalService) {
	
							ngDialog.closeAll();

                           var nav = angular.element('nav');

                           if (nav) {
                               nav.hide();
                           }

                           var cfg = gobalService.config();

                           userService.getAgreement(cfg.sysKey).then(function (result) {

                               $scope.agreement = $sce.trustAsHtml(result);

                           });

                           $scope.back = function () {
                               $window.history.back();
                           }

                       });

//收费标准
controllers.controller('AreaCtrl',
                       function ($scope, $rootScope, $sce, $window, userService, paotuiService,
                                 gobalService, locationService) {

                           var nav = angular.element('nav');
                           if (nav) {
                               nav.hide();
                           }

                           var cfg = gobalService.config();

                           if (isFromWx()) {
                               if ($rootScope.openId) {
                                   userService.findWxBind(cfg.sysKey, $rootScope.openId)
                                       .then(function (result) {
                                           if (result.code == 0) {
                                               var bindData = result.data;
                                               $scope.passengerId = bindData.passengerId;

                                               $rootScope.passengerId = bindData.passengerId;
                                           }
                                       });
                               } else {
                                   $location.path('/index'); //跳转到首页
                               }

                           } /*else {
                               $scope.passengerId = 31;
                           }*/

                           var promise = locationService.locateMe($rootScope);

                           userService.queryarea(cfg.sysKey, cfg.ack, $scope.passengerId,
                                                 promise.$$state.value.point.lat,
                                                 promise.$$state.value.point.lng)
                               .then(function (result) {
                                   $scope.area = result.data;

                               });

                           $scope.back = function () {
                               $window.history.back();
                           }

                       });

controllers.controller('AreaZhuanCtrl',
                       function ($scope, $rootScope, $sce, $window, userService, paotuiService,
                                 gobalService, locationService, zhuancheService) {

                           var nav = angular.element('nav');
                           if (nav) {
                               nav.hide();
                           }

                           var cfg = gobalService.config();

                           if (isFromWx()) {
                               if ($rootScope.openId) {
                                   userService.findWxBind(cfg.sysKey, $rootScope.openId)
                                       .then(function (result) {
                                           if (result.code == 0) {
                                               var bindData = result.data;
                                               $scope.passengerId = bindData.passengerId;

                                               $rootScope.passengerId = bindData.passengerId;
                                           }
                                       });
                               } else {
                                   $location.path('/index'); //跳转到首页
                               }

                           } /*else {
                               $scope.passengerId = 31;
                           }*/

                           var promise = locationService.locateMe($rootScope);

                           //查询车辆类型
                           var promise2 = zhuancheService.getCarTypesV4(cfg.sysKey,
                                                                        $scope.passengerId,promise.$$state.value.point.lat,promise.$$state.value.point.lng);

                           promise2.then(function (carTypes) {
                               $scope.carTypes = carTypes;

                           });
                           $scope.hideServerTypeList = true;
                           $scope.showSelect = function () {
                        	   $scope.hideServerTypeList = true;
                               $scope.hideCarTypeList = false;
                           }
                           $scope.selectCarType = function (carType) {
                               $scope.carType = carType;
                        	   $scope.serverTypes = carType.serverTypes;
                               $scope.hideCarTypeList = true;
                               $scope.hideServerTypeList = false;
                               
                           }
                           $scope.selectServerType = function (serverType) {
                        	   $scope.serverType = serverType;
                               $scope.hideServerTypeList = true;

                               userService.queryzhuanarea(cfg.sysKey,$scope.serverType.typeId)
                                   .then(function (result) {
                                       $scope.area = result.data;

                                   });
                           }
                           $scope.back = function () {
                               $window.history.back();
                           }

                       });

controllers.controller('AreaErrandCtrl',
                       function ($scope, $rootScope, $sce, $window, userService, paotuiService,
                                 zhuanxianService, gobalService, locationService) {

                           var nav = angular.element('nav');
                           if (nav) {
                               nav.hide();
                           }

                           var cfg = gobalService.config();

                           if (isFromWx()) {
                               if ($rootScope.openId) {
                                   userService.findWxBind(cfg.sysKey, $rootScope.openId)
                                       .then(function (result) {
                                           if (result.code == 0) {
                                               var bindData = result.data;
                                               $scope.passengerId = bindData.passengerId;

                                               $rootScope.passengerId = bindData.passengerId;
                                           }
                                       });
                               } else {
                                   $location.path('/index'); //跳转到首页
                               }

                           } /*else {
                               $scope.passengerId = 31;
                           }*/

                           var promise = locationService.locateMe($rootScope);
                           var promise2 = paotuiService.getServiceTypes(cfg.sysKey, cfg.ack,
                                                                        $scope.passengerId,
                                                                        promise.$$state.value.point.lat,
                                                                        promise.$$state.value.point.lng)
                           promise2.then(function (types) {

                               $scope.types = types;

                           });

                           $scope.showSelect = function () {
                               $scope.hideTypeList = false;
                           }
                           $scope.selectType = function (type) {
                               $scope.type = type;
                               $scope.hideTypeList = true;

                               userService.queryerrandarea(cfg.sysKey, cfg.ack, $scope.passengerId,
                                                           $scope.type.id,promise.$$state.value.point.lat,
                                                           promise.$$state.value.point.lng).then(function (result) {
                                   $scope.area = result.data;

                               });
                           }

                           $scope.back = function () {
                               $window.history.back();
                           }

                       });
controllers.controller('AssessCtrl',
                       function ($scope, $rootScope, $routeParams, $sce, $window, $location,
                                 daijiaService, gobalService, locationService, driverService,
                                 ngDialog,zhuancheService, zhuanxianService, paotuiService) {

							ngDialog.closeAll();
                           var nav = angular.element('nav');
                           if (nav) {
                               nav.hide();
                           }
                           var cfg = gobalService.config();
                           driverService.findDriver(cfg.sysKey, $routeParams.driverId)
                               .then(function (result) {
                                   if (result.success) {
                                       $scope.driverInfo = result;

                                   }

                               })
                           $scope.submitReview = function () {
                               if (!$("#score").val()) {
                                   alert('请点击评价等级星星');
                                   return;
                               }
                               
                               if ($routeParams.type == 'daijia') {
                                   //评价代驾
                                   daijiaService.daijiaOrderReview($routeParams.phone,
                                                                   $routeParams.driverId,
                                                                   $routeParams.orderId,
                                                                   $("#score").val(),
                                                                   $scope.content, cfg.sysKey)
                                       .then(function (result) {
                                           if (result.code == 0) {
                                               alert("评价成功");
                                               $location.path('/index');//跳转到首页
                                           } else {
                                               $location.path('/index');//跳转到首页

                                           }
                                       });

                               }
                               else if ($routeParams.type == 'zhuanche') {
                                   //评价专车
                                   zhuancheService.zhuanOrderReview($routeParams.orderId,
                                                                    $("#score").val(),
                                                                    $scope.content, cfg.sysKey)
                                       .then(function (result) {
                                           if (result.code == 0) {
                                               alert("评价成功");
                                               $location.path('/index');//跳转到首页
                                           } else {
                                               $location.path('/index');//跳转到首页

                                           }
                                       });

                               } else if ($routeParams.type == 'paotui') {
                                   //评价跑腿
                                   paotuiService.errandOrderReview($routeParams.orderId,
                                                                   $("#score").val(),
                                                                   $scope.content, cfg.sysKey)
                                       .then(function (result) {
                                           if (result.code == 0) {
                                               alert("评价成功");
                                               $location.path('/index');//跳转到首页
                                           } else {
                                               $location.path('/index');//跳转到首页

                                           }
                                       });
                               } else if ($routeParams.type == 'zhuanxian') {
                                   //评价专线
                                   zhuanxianService.zhuanxianOrderReview($routeParams.orderId,
                                                                         $("#score").val(),
                                                                         $scope.content, cfg.sysKey)
                                       .then(function (result) {
                                           if (result.code == 0) {
                                               alert("评价成功");
                                               $location.path('/index');//跳转到首页
                                           } else {
//					alert(result.message);
                                               $location.path('/index');//跳转到首页

                                           }
                                       });
                               }

                           }

                       });




